Xslt 如何为有效负载xsl设置名称空间前缀
我有这个负载,我想知道的是如何将这个“TV:”名称空间前缀添加到其中的所有节点和元素Xslt 如何为有效负载xsl设置名称空间前缀,xslt,xpath,namespaces,prefix,Xslt,Xpath,Namespaces,Prefix,我有这个负载,我想知道的是如何将这个“TV:”名称空间前缀添加到其中的所有节点和元素 <TVInqResponse> <TVInqRS> <StatusCode>0</StatusCode> <StatusDescription>Success</StatusDescription> This is what is expect to have as a r
<TVInqResponse>
<TVInqRS>
<StatusCode>0</StatusCode>
<StatusDescription>Success</StatusDescription>
This is what is expect to have as a result:
<**tv**:TVInqResponse>
<**tv**:TVInqRS>
<**tv**:StatusCode>0</**tv**:StatusCode>
<**tv**:StatusDescription>Success</**tv**:StatusDescription>
0
成功
这就是预期的结果:
0
成功
此转换:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tv="some:tv">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:element name="tv:{name()}" namespace="some:tv">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
<tv:TVInqResponse xmlns:tv="some:tv">
<tv:TVInqRS>
<tv:StatusCode>0</tv:StatusCode>
<tv:StatusDescription>Success</tv:StatusDescription>
</tv:TVInqRS>
</tv:TVInqResponse>
<xsl:template match="@*">
<xsl:attribute name="tv:{name()}" namespace="some:tv">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
应用于此XML文档时(基于提供的格式错误的“playload”…):
0
成功
生成所需的正确结果:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tv="some:tv">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:element name="tv:{name()}" namespace="some:tv">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
<tv:TVInqResponse xmlns:tv="some:tv">
<tv:TVInqRS>
<tv:StatusCode>0</tv:StatusCode>
<tv:StatusDescription>Success</tv:StatusDescription>
</tv:TVInqRS>
</tv:TVInqResponse>
<xsl:template match="@*">
<xsl:attribute name="tv:{name()}" namespace="some:tv">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
0
成功
如果您还希望任何属性名称位于同一名称空间中,请将模板匹配属性替换为该名称:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tv="some:tv">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:element name="tv:{name()}" namespace="some:tv">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
<tv:TVInqResponse xmlns:tv="some:tv">
<tv:TVInqRS>
<tv:StatusCode>0</tv:StatusCode>
<tv:StatusDescription>Success</tv:StatusDescription>
</tv:TVInqRS>
</tv:TVInqResponse>
<xsl:template match="@*">
<xsl:attribute name="tv:{name()}" namespace="some:tv">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>