Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 如何为有效负载xsl设置名称空间前缀_Xslt_Xpath_Namespaces_Prefix - Fatal编程技术网

Xslt 如何为有效负载xsl设置名称空间前缀

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

我有这个负载,我想知道的是如何将这个“TV:”名称空间前缀添加到其中的所有节点和元素

<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>