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