I've got a stupid question.
I am loading an external document, and then using it to add an attribute to a certain element in the main document. A bit like this:
<xsl:variable name="dictstrings" select="document($dictionary_file)"/>
<xsl:key name="ui_ids" match="DICT_ENTRY" use="LANG_ENTRY"/>
<!--Identity template, copies all content -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--Template for uicontrol that provides custom behavior -->
<xsl:template match="uicontrol[key('ui_ids', ., $dictstrings)]">
<xsl:apply-templates select="key('ui_ids', ., $dictstrings)"/>
</xsl:template>
This matches the appropriate LANG_ENTRY element(s) in the external document to the corresponding uicontrol
element in the main document. (I have another xsl:template
command that adds the DICT_ID attribute.) All good so far.
My problem is that sometimes the LANG_ENTRY element in my $dictionary_file starts with an extraneous ampersand. Like so:
<DICT_ENTRY DICT_ID="21625">
<LANG_ENTRY><![CDATA[Test list]]></LANG_ENTRY>
</DICT_ENTRY>
<DICT_ENTRY DICT_ID="2163">
<LANG_ENTRY><![CDATA[&Insert new test]]></LANG_ENTRY>
</DICT_ENTRY>
I'd like to strip this ampersand out. Otherwise, the match won't work.
I was trying to do this, in a vague dreamy haze:
<xsl:variable name="dictstrings">
<xsl:apply-templates select="document($dictionary_file)"/>
</xsl:variable>
and then have a template that caught the LANG_ENTRY
<xsl:template match="LANG_ENTRY[starts-with(.,'&')]">
<xsl:element name="LANG_ENTRY">
<xsl:value-of select="substring(.,2)"/>
</xsl:element>
</xsl:template>
But, as you know, it objects to the declaration of the dictstrings variable, now, saying
XTDE0640: Circular variable or parameter declaration
How should I go about parsing and editing the external document nodes, before using them in the key() function?
I am also nervous about making sure the context is correct between the main and the external document, but I haven't got to that problem yet.