有这样一个需求:
<><><><>

解决方案 »

  1.   

    误操作,
    需求是这样的:
    <Root>
     <Level>A</Level>
     <Elem1>value1</Elem1>
     <Elem2>value2</Elem2>
     ... ...
    </Root>
    转换成:
    <Root>
     <Level>B</Level>
     <Elem1>value1</Elem1>
     <Elem2>value2</Elem2>
    </Root>
    即替换某个特定标签上的值,xsl 如何写?
      

  2.   


    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="Level">
            <xsl:copy>
                <xsl:text>B</xsl:text>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"  />
            </xsl:copy>
        </xsl:template>  
    </xsl:stylesheet>
      

  3.   


    感谢 icy_csdn,但是这个我不是很理解,能否简单解释下;<xsl:copy></xsl:copy>是复制标签吗?"@*|node()"是匹配什么,为什么是这样写?谢谢。
      

  4.   

    node()是内部函数?没查到它的用法,高手解释下?
      

  5.   

    1. <xsl:copy></xsl:copy>是复制的意思没错,可以复制当前element,但不包括它的属性及子结点;
    2. <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"  />
            </xsl:copy>
        </xsl:template>
    这一段的代码是指,复制源XML中的内容。这样除Level你改变了值外,其他信息都只是复制过来。
      

  6.   

    还是有些不太明白的,算了,结贴了,有时间自己再研究,感谢icy_csdn