I'm working through my first major XSLT project, and am a bit of a novice, so please be patient with my ignorance.
Our group is working on a transform of existing XMLs to an entirely different tagging system. I have devised a system of processing the MathType callouts (signified by "${TEXT}" ) using Analyze-String, but I'm having difficulty determining what I should do with code like the ital tags (signified by the "I" tags), which need to be kept in the result code.
I tried using copy-of in the non-matching-substring, but that appears to not work. Of course, value-of gets me everything except the ital tags.
I realize the variable ($stemString) is superfluous at this point. I was going along that path thinking I might be able to come up with something that would allow copy-of to process, but so far, no luck.
Sample Code:
<stem>What is the value of <I>f</I>(<I>x</I>) when ${##A112800eqn01:3}</stem>
My current XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="assessmentItem">
<!--SNIP-->
<xsl:apply-templates select="stemArea/stem"/>
<!--SNIP-->
</xsl:template>
<xsl:template match="stem">
<xsl:variable name="stemString">
<xsl:copy-of select="./* | ./text()"/>
</xsl:variable>
<xsl:choose>
<!--Tests for empty stems that aren't art callouts-->
<xsl:when test=". = '' and @type!='art'"></xsl:when>
<xsl:when test=". = ' ' and @type!='art'"></xsl:when>
<!--Test for art callouts-->
<xsl:when test="@type='art'"><p><img alt="{@loc}" height="10" id="{@loc}" label="" longdesc="normal" src="{@loc}" width="10"/></p></xsl:when>
<!--Test for boxed text-->
<xsl:when test="@style='box' or @style='boxL'"><p><span label="Tag_7">
<xsl:copy-of select="./* | ./text()"></xsl:copy-of>
</span></p></xsl:when>
<xsl:otherwise><p>
<!--Are MathType tokens present in stem?-->
<xsl:analyze-string regex="(\$\{{.+\}})" select="$stemString">
<!--If MathType tokens are in stem, do the following-->
<xsl:matching-substring>
<xsl:analyze-string regex="(\$\{{)(##.+[eqn|art]\d+)([^a-zA-Z0-9]?.*\}})" select=".">
<xsl:matching-substring>
<img alt="{regex-group(2)}" height="10" id="{regex-group(2)}" label="" longdesc="normal" src="{regex-group(2)}" width="10"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:text>ERROR</xsl:text>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:matching-substring>
<!--No MathType tokens in string-->
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</p></xsl:otherwise>
</xsl:choose>
</xsl:template>
Desired Output:
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/></p>
What I'm getting:
<p>What is the value of f(x) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/></p>
Anyone have any ideas for how to proceed?
@Martin Honnen: Thank you for the response. Your code solves the error.
However, I have an additional issue. When there is more than one MathType callout in a stem, it causes an error. I am sure that the cause is my regex not capturing everything properly, but I have hammered on this for a while to no avail. Below I will illustrate the issue I'm having.
Sample Code:
<stem type="text">What is the value of <I>f</I>(<I>x</I>) when ${##A112800eqn01:3}, and ${##A112800eqn02:3} is 3.</stem>
Desired Output:
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01" height="10" id="##A112800eqn01" label="" longdesc="normal" src="##A112800eqn01" width="10"/>, and <img alt="##A112800eqn02" height="10" id="##A112800eqn02" label="" longdesc="normal" src="##A112800eqn02" width="10"/> is 3.</p>
What I'm getting:
<p>What is the value of <I>f</I>(<I>x</I>) when <img alt="##A112800eqn01:3}, and ${##A112800eqn02" height="10" id="##A112800eqn01:3}, and ${##A112800eqn02" label="" longdesc="normal" src="##A112800eqn01:3}, and ${##A112800eqn02" width="10"/> is 3.</p>