[XSLT难题]
源xml文件如下,现在需要通过xslt转换得到一个新的xml文件,新xml中要把源xml中的<Dyna>元素中的x,y属性的值对调,其它部分保持和源xml一致
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="trans.xslt"?>
<source>
<title>XSL</title>
<author>John Smith</author>
<Dyna x="123" y="456">V1.0.0.0</Dyna>
</source>
转换xslt文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="node()"/>
</xsl:template>
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="name()='Dyna'">
<xsl:call-template name="DynaTemplate"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="DefaultTemplate"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="DynaTemplate">
<xsl:copy>
<xsl:variable name="temp">
<xsl:value-of select="@x"/>
</xsl:variable>
<xsl:attribute name="x"><xsl:value-of select="@y"/></xsl:attribute>
<xsl:attribute name="y"><xsl:value-of select="$temp"/></xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template name="DefaultTemplate">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
得到的xml文件如下,没有达到预期的结果:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="trans.xslt"?>
<source/>
请高手指点一下,该如何修改xslt以达到预期的结果呢,谢谢