我可以把它加入了 前綴默認命名空間(該 最後一個)的工作,但我怎麼會輸出一個 XML沒有添加前綴,它是 可以通過使用XslCompiledTransform 。 NET 4?
這裏是一個具體的例子,如何做到這一點:
這種轉變:
<xsl:stylesheet version="1.0"
xmlns="http://workflow.converga.com.au/compass"
xmlns:c="http://workflow.converga.com.au/compass"
xmlns:ext="http://exslt.org/common"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="c ext xsl">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pnewItem">
<item name="wine">
<price>3</price>
<quantity>5000</quantity>
</item>
</xsl:param>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="c:item[last()]">
<xsl:call-template name="identity"/>
<xsl:copy-of select="ext:node-set($pnewItem)/*"/>
</xsl:template>
</xsl:stylesheet>
當XslCompiledTransform以下XML文檔應用:
<pExport xmlns="http://workflow.converga.com.au/compass">
<Goods>
<item name="tobacco">
<price>5</price>
<quantity>1000</quantity>
</item>
</Goods>
</pExport>
產生想(同一個XML文檔添加了一個新的項目),正確的結果:
<pExport xmlns="http://workflow.converga.com.au/compass">
<Goods>
<item name="tobacco">
<price>5</price>
<quantity>1000</quantity>
</item>
<item name="wine">
<price>3</price>
<quantity>5000</quantity>
</item>
</Goods>
</pExport>
你似乎意味着你可以*不*找到一種方法來使它與默認名稱空間一起工作,而無需向輸出XML添加前綴。那種方式不起作用?當你不添加前綴時,觀察到的行爲是什麼?你用XSLT標記了這個,所以你的意思是XSLT處理器不能識別工作流/羅盤命名空間中的pExport元素?需要更多信息。這可能有助於顯示樣式表的相關部分。 – LarsH 2010-09-06 06:38:02
好問題(+1)。查看我的答案,瞭解具體示例和所用解決方案。 – 2010-09-06 17:11:41
LarsH,是的我的意思是,如果不添加前綴,輸出XSLT將無法匹配具有默認名稱空間的節點(不帶標籤)。我正在尋找一種方法來匹配這些元素,而無需爲默認名稱空間添加我自己的前綴。 – 2010-09-06 21:51:41