Xml XSLT在密钥中使用前解析文档($file)

Xml XSLT在密钥中使用前解析文档($file),xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我有一个愚蠢的问题 我正在加载一个外部文档,然后使用它向主文档中的某个元素添加属性。有点像这样: <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: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>
我想把这个符号去掉。否则,比赛就不会成功

我正试图在朦胧的梦幻中做到这一点:

<xsl:variable name="dictstrings">
    <xsl:apply-templates select="document($dictionary_file)"/>
</xsl:variable>
在键函数中使用外部文档节点之前,我应该如何解析和编辑它们


我还担心主文档和外部文档之间的上下文是否正确,但我还没有解决这个问题。

您实际上不需要编辑外部节点,只需确保键定义中的use表达式去掉前导符号,如果有,则,当它构造键值时:

<xsl:key name="ui_ids" match="DICT_ENTRY" use="replace(LANG_ENTRY, '^&amp;', '')"/>

您没有这么明确地说,但我假设您使用的是XSLT2.0,因为您在匹配模式中使用了变量,并且使用了键函数的三参数形式。

谢谢。非常简单,工作非常完美。我还在学习这一切。
<xsl:template match="LANG_ENTRY[starts-with(.,'&amp;')]">
    <xsl:element name="LANG_ENTRY">
        <xsl:value-of select="substring(.,2)"/>
    </xsl:element>
</xsl:template>
XTDE0640: Circular variable or parameter declaration
<xsl:key name="ui_ids" match="DICT_ENTRY" use="replace(LANG_ENTRY, '^&amp;', '')"/>