1
這裏我的XML文檔轉換XML文檔的結構:如何使用XSLT
<?xml version="1.0" ?>
<ArrayOfPrimitiveParameter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PrimitiveParameter>
<Name>field</Name>
<Value xsi:type="xsd:string">TNA</Value>
</PrimitiveParameter>
<PrimitiveParameter>
<Name>date</Name>
<Value xsi:type="xsd:dateTime">2011-12-14T00:00:00</Value>
</PrimitiveParameter>
</ArrayOfPrimitiveParameter>
而且我要在改造其結構:
TNA 2011-12-14T00:00:00
的那一刻,我寫了這個:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="/">
<Parameters>
<xsl:apply-templates/>
</Parameters>
</xsl:template>
<xsl:template match="ArrayOfPrimitiveParameters">
<!-- String -->
<xsl:if test="PrimitiveParameter/@xsi:type = 'xsd:string'">
<StringParameter>
<xsl:attribute name="name">
<xsl:value-of select='PrimitiveParameter/name' />">
</xsl:attribute>
<xsl:value-of select='PrimitiveParameter/value'/>
</StringParameter>
</xsl:if>
<!-- DateTime -->
<xsl:if test="PrimitiveParameter/@xsi:type = 'xsd:dateTime'">
<DateParameter>
<xsl:attribute name="name">
<xsl:value-of select='PrimitiveParameter/name' />">
</xsl:attribute>
<xsl:value-of select='PrimitiveParameter/value'/>
</DateParameter>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
,但我的XML的輸出是:
<?xml version="1.0" encoding="utf-8"?><Parameters xmlns="http://www.w3.org/TR/REC-html40" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
field
TNA
date
2011-12-14T00:00:00
</Parameters>
感謝你的幫助,
弗洛裏安
我試試這個,謝謝! – Florian
它工作正常!非常感謝你 ! – Florian