Assigning variable a certain token from tokenized string [xslt]



I'm trying to assign a variable a certain token from a large string. I first tokenize the string, then for each token I check if it contains a certain substring. If it does, I want to assign that token to the variable.


Lastly, I use that variable to set an attribute of a div.


I've tried this code below, which gives me the exact output i want in oXygen XML Editor. However, when I run the XML/XSLT file in IE (11), it simply just prints out the entire original string, meaing xhtmlVar in the XSLT below. The div doesn't even show up (it might be there in DOM, but I don't visually see it -- I'll recheck this momentarily).


XSLT



<!-- xhtmlVar variable is a large string -->
<xsl:variable name="xhtmlVar" select="metadata[@element='xhtml_head_item']"></xsl:variable>

<xsl:variable name="quoteChar">"</xsl:variable> <!-- for cleaning token below -->
<xsl:variable name="tokenized" select="tokenize($xhtmlVar,' ')"/>
<xsl:variable name="doi">
<xsl:for-each select="$tokenized">
<xsl:variable name="curtoken" select="."/>
<!-- if token contains the string 'doi', assign it to the variable -->
<xsl:if test="contains($curtoken, 'doi')">
<!-- return value while stripping some stuff (token looks like this: doi:asdasdasd") -->
<xsl:value-of select="translate(replace($curtoken, 'doi:', ''),$quoteChar,'')"></xsl:value-of>
</xsl:if>
</xsl:for-each>
</xsl:variable>

<!-- pass $doi variable as attribute value in a div -->
<div type='medium' class='embed' handle='{$doi}'></div>


How can I achieve what I want? Am I doing something wrong? Any tips on how to more gracefully write the code above is also appreciated!


Thanks in advance!


No comments:

Post a Comment