0
我有這樣的XML:XSL添加新元素名稱空間
<Row>
<one>1</one>
<two>2</two>
<tree>3</tree>
<four>4</four>
<five>5</five>
</Row>
和IM希望得到的結果:
<n0:Result xmlns:ns0="http://www.my.schemas/schemas/event1.xsd"
xmlns:ns1="http://www.my.schemas/schemas/event2.xsd"
xmlns:ns2="http://www.my.schemas/schemas/event3.xsd">
<n1:group1>
<n2:one>1</n2:one>
<n2:two>2</n2:two>
</n1:group1>
<n1:group2>
<n2:tree>3</n2:tree>
<n2:four>4</n2:four>
</n1:group2>
<n0:five>5</n0:five>
</Result>
我現在XSL是:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://www.my.schemas/schemas/event1.xsd"
xmlns:ns1="http://www.my.schemas/schemas/event2.xsd"
xmlns:ns2="http://www.my.schemas/schemas/event3.xsd" >
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Row">
<result>
<group1>
<xsl:apply-templates select="one|two"/>
</group1>
<group2>
<xsl:apply-templates select="tree|four"/>
</group2>
<xsl:apply-templates select="five"/>
</result>
</xsl:template>
</xsl:stylesheet>
怎麼辦我將所需的名稱空間添加到新舊元素? 我不知道如何做到這一點與分組和新元素,只與現有的元素。
我試過了,但如果你只是寫N0:導致XSL,你會得到結果和NO N0 – lshaked 2014-11-03 09:14:11
@Ishaked,我已經編輯了答案,並試圖展示如何來轉換其他元素,使它們最終進入名稱空間。 – 2014-11-03 09:27:24
太好了,謝謝!工作:) – lshaked 2014-11-03 09:39:37