Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT1.0根据映射重写节点的值_Xslt - Fatal编程技术网

XSLT1.0根据映射重写节点的值

XSLT1.0根据映射重写节点的值,xslt,Xslt,转换文档时,我需要在“映射”中“查找”某些节点内容,并写入这些值 我在转换中内联了我的“地图” <xsl:variable name="inlinedmap"> <kat id="stuff">value</kat> <!-- ... --> </xsl:variable> <xsl:variable name="map" select="document('')/xsl:stylesheet/xsl:variab

转换文档时,我需要在“映射”中“查找”某些节点内容,并写入这些值

我在转换中内联了我的“地图”

<xsl:variable name="inlinedmap">
    <kat id="stuff">value</kat>
    <!-- ... -->
</xsl:variable>
<xsl:variable name="map" select="document('')/xsl:stylesheet/xsl:variable[@name='inlinedmap']" />
<xsl:template match="/">
    <xsl:for-each select="/*/foo">
        <!-- 'bar' contents should equal to contents of 'kat' -->
        <xsl:variable name="g" select="$map/key[.=bar]"/>
        <xsl:choose>
            <xsl:when test="$g != ''">
                <xsl:value-of select="$g/@id"/>
            </xsl:when>
            <xsl:otherwise>
                ERROR
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>

价值
错误
我总是得到错误值。 我不能将映射值放入属性中,因为它们包含转义的字母


我如何才能让它工作?

我认为这里有几个问题:

  • 您似乎在变量中寻找
    key
    元素,但它们在那里被称为
    kat
    (打字?)
  • 您似乎试图引用循环中上下文节点的
    子节点,但需要使用
    current()
  • 您应该在自己的命名空间中将此映射创建为元素,而不是
    xsl:variable
这里有一个完整的例子。此样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:my="my">
    <my:vars>
        <kat id="stuff">value</kat>
        <!-- ... -->
    </my:vars>
    <xsl:variable name="map" select="document('')/*/my:vars/*"/>
    <xsl:template match="/">
        <xsl:for-each select="/*/foo">
            <!-- 'bar' contents should equal to contents of 'kat' -->
            <xsl:variable name="g" select="$map[.=current()/bar]"/>
            <xsl:choose>
                <xsl:when test="$g != ''">
                    <xsl:value-of select="$g/@id"/>
                </xsl:when>
                <xsl:otherwise>
                    ERROR
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

@ŁukaszGruner:这就像“从窗户里看,天还在下雨”一样信息丰富。您首先没有提供源XML文档。你也没有提供一个完整的转变。更不用说想要的结果了。。。如果人们不能纠正你的问题,那可能只是你想象力的产物!请编辑并改进您的问题。另外,请向少数勇敢的人表示更多的敬意,他们可能敢于并试图猜测你的真实意思。如果工作正常,主要问题(答案中解释的内容除外)是我的地图编码
<root>
    <foo><bar>value</bar></foo>
    <foo><bar>value1</bar></foo>
    <foo><bar>value2</bar></foo>
    <foo><bar>value3</bar></foo>
</root>
stuff
ERROR
ERROR
ERROR