小编MTS*_*MTS的帖子

XSLT 1.0如何在document()函数中使用xsl:key

我正在尝试使用xsl:key来使用XSL document()函数查找外部XML文档中的项目.我可以让xsl:key部分工作,如果,而不是使用document(),我只是合并两个XML文件(在C#中使用XmlDocument).然而,两个XML文件都非常大,并且在某些情况下我开始出现"内存不足"错误.此外,我需要能够使用xls:key,否则该过程需要数小时.

在XSLT 2.0中,我相信你可以这样做:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:variable name="lookupDoc" select="document('CodeDescriptions.xml')" />
    <xsl:key name="LookupDescriptionByCode" match="Code/@description" use="../@code" />

    <xsl:template match="ItemCode">
        <xsl:call-template name="MakeSpanForCode">
            <xsl:with-param name="code" select="text()" />
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="MakeSpanForCode">
        <xsl:param name="code" />
        <xsl:element name="span">
            <xsl:attribute name="title">
                <xsl:value-of select="$lookupDoc/key('LookupDescriptionByCode', $code)" />
            </xsl:attribute>
            <xsl:value-of select="$code" />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

你如何在XSLT 1.0中实现这一目标?

document xslkey xslt-1.0

5
推荐指数
1
解决办法
5304
查看次数

使用XSLT key()函数根据单独元素中的两个属性查找节点

我正在尝试使用XSLT key()函数返回<Code>XML文件中符合以下两个条件的所有元素:

Code[code=$code] AND ancestor::CodeType[type=$codeType]`
Run Code Online (Sandbox Code Playgroud)


以下是输入XML的简单示例:

<Items>
    <Item code-number="C1" category="ABC" />
    <Item code-number="C3" category="ABC" />
    <Item code-number="C1" category="XYZ" />
</Items>

<CodeTypes>
    <CodeType type="ABC">
        <SubType title="Category III Codes">   <!-- <SubType> elements are optional -->
            <SubType title="Subcategory III-15 Codes">
                <Code code="C1" description="Red" />
                <Code code="C2" description="Green" />
                <Code code="C3" description="Blue" />
                <Code code="C3" description="Purple" />   <!-- Same code can appear more than once -->
            </SubType>
        </SubType>
    <CodeType>
    <CodeType type="XYZ">
        <Code code="C1" description="Black" />   <!-- Same code can be used for …
Run Code Online (Sandbox Code Playgroud)

xslt xslkey

2
推荐指数
1
解决办法
9331
查看次数

标签 统计

xslkey ×2

document ×1

xslt ×1

xslt-1.0 ×1