0
InputXML:轉化與命名空間
<json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<json:object name="Customers">
<json:array name="Order">
<json:object>
<json:string name="Name">john</json:string>
<json:string name="Password">Doe</json:string>
</json:object>
<json:object>
<json:string name="Name">Adam</json:string>
<json:string name="Password">eve</json:string>
</json:object>
</json:array>
</json:object>
</json:object>
XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:tns="http://some-other-namespace" xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx" exclude-result-prefixes="json">
<xsl:template match="/json:object">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="json:array[@name]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="json:object[@name]">
<xsl:element name="{@name}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="json:object">
<xsl:element name="{../@name}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="json:string[@name]">
<xsl:element name="{@name}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
實際輸出:
<Customers>
<Order>
<Name>john</Name>
<Password>Doe</Password>
</Order>
<Order>
<Name>Adam</Name>
<Password>eve</Password>
</Order>
</Customers>
所需的輸出:
<Customers xmlns:tns="http://some-other-namespace">
<Order>
<Name>john</Name>
<Password>Doe</Password>
</Order>
<Order>
<Name>Adam</Name>
<Password>eve</Password>
</Order>
</Customers>
我知道我們可以做到通過將實際輸出作爲其輸入的身份在另一個XSL轉換,並獲得我所需的輸出。
但我想在一個單一的樣式表中做所有事情。如何實現使用單個xsl
您的預期結果沒有多大意義。它和實際輸出之間的唯一區別是**未使用的**名稱空間聲明。對接收應用程序完全不應有任何改變。 – 2014-09-22 21:20:56
我同意。但是我想用它來進行模式驗證 – mnvbrtn 2014-09-22 23:09:23