0
我有如下一個xml:複製所有節點排除修改的節點
<root>
<book>abcd</book>
<pen>ghi</pen>
<source Qual="poor" vise="n">
<source>
<input value="in"></input>
<input></input>
</source>
</source>
<class>ab</class>
<source>noaatributes</source>
<studio>ghi</studio>
<source Qual="good" vise="m">
<source>
<input></input>
<input value="out"></input>
</source>
</source>
</root>
我想將XML轉換在下面的格式:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<book>abcd</book>
<pen>ghi</pen>
<poor value="in"/>
<class>ab</class>
<source>noaatributes</source>
<studio>ghi</studio>
<good value="out"/>
</root>
,但我寫的代碼是不是給出所需的輸出..我卡在我的代碼中間..任何建議請。 這是迄今爲止我所編寫的代碼:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:apply-templates select="@* | node()" />
</xsl:template>
<xsl:template match="source/@Qual">
<xsl:text disable-output-escaping="yes" ><![CDATA[
<]]></xsl:text>
<xsl:value-of disable-output-escaping="yes" select="."/>
</xsl:template>
<xsl:template match="source/source">
<xsl:apply-templates select="input"/>
<xsl:text disable-output-escaping="yes" ><![CDATA[
/>]]></xsl:text>
</xsl:template>
<xsl:template match="input">
<xsl:if test ="string-length(./@value) > 0">
<xsl:text disable-output-escaping="yes" ><![CDATA[
]]></xsl:text>
<xsl:text disable-output-escaping="yes" ><![CDATA[Value="]]></xsl:text>
<xsl:value-of disable-output-escaping="yes" select="./@value"/>
<xsl:text disable-output-escaping="yes" ><![CDATA[" ]]></xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
完美的代碼...感謝... – Blossom