Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
面临使用XSL将XML转换为其他XML的问题_Xml_Xslt - Fatal编程技术网

面临使用XSL将XML转换为其他XML的问题

面临使用XSL将XML转换为其他XML的问题,xml,xslt,Xml,Xslt,我需要将这个标记添加到我现有的XML模式中。我试图通过XSL转换来实现这个结果,但是没有得到想要的输出。下面提到了我的模式示例和XSL XML:1 <decreaseStickerVO> <taxOfficeCod>04.20</taxOfficeCod> <vehicleDetailsVOList> <VehicleDetailsVO> <chassis>878JHJH</chassis>

我需要将
这个标记添加到我现有的XML模式中。我试图通过XSL转换来实现这个结果,但是没有得到想要的输出。下面提到了我的模式示例和XSL

XML:1

<decreaseStickerVO>
    <taxOfficeCod>04.20</taxOfficeCod>
 <vehicleDetailsVOList>
    <VehicleDetailsVO>
 <chassis>878JHJH</chassis>
<circulationTax>6750</circulationTax>
<cylinderCapacity>De 1.801 c.c. a 2.400 c.c.</cylinderCapacity>
<registration>LD-11-11-KK</registration>
<registrationDate>2019-01-01</registrationDate>
<sealNum>K</sealNum>
<vehicleBrand>K</vehicleBrand>
<vehicleExemption>false</vehicleExemption>
<vehicleModel>K</vehicleModel>
<vehicleType>Ligeiros</vehicleType>
    </VehicleDetailsVO>
    <VehicleDetailsVO>
<chassis>878JHJHJ</chassis>
<circulationTax>2450</circulationTax>
<cylinderCapacity>De 126 c.c. a 450 c.c.</cylinderCapacity>
<registration>LDA-44-44</registration>
<registrationDate>2019-01-01</registrationDate>
<sealNum>K</sealNum>
<vehicleBrand>K</vehicleBrand>
<vehicleExemption>false</vehicleExemption>
<vehicleModel>K</vehicleModel>
<vehicleType>Motociclos</vehicleType>
    </VehicleDetailsVO>
     </vehicleDetailsVOList>
 </decreaseStickerVO>

4.20
878JHJH
6750
De 1.801 c.c.a 2.400 c.c.c。
LD-11-11-KK
2019-01-01
K
K
假的
K
利盖罗斯
878JHJ
2450
De 126 c.c.a 450 c.c。
LDA-44-44
2019-01-01
K
K
假的
K
莫托西克洛斯
使用XSL

XSL示例:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/decreaseStickerVO">
<decreaseStickerVO>
<taxOfficeCod>
  <xsl:value-of select="taxOfficeCod"/>
  </taxOfficeCod>
    <vehicleDetailsVOList>
      <xsl:for-each select="VehicleDetailsVO">
        <VehicleDetailsVO>
          <chassis>
            <xsl:value-of select="chassis"/>
          </chassis>
          <circulationTax>
            <xsl:value-of select="circulationTax"/>
          </circulationTax>
          <cylinderCapacity>
            <xsl:value-of select="cylinderCapacity"/>
          </cylinderCapacity>
          <registration>
            <xsl:value-of select="registration"/>
          </registration>
          <registrationDate>
            <xsl:value-of select="registrationDate"/>
          </registrationDate>
          <sealNum>
            <xsl:value-of select="sealNum"/>
          </sealNum>
          <vehicleBrand>
            <xsl:value-of select="vehicleBrand"/>
          </vehicleBrand>
          <vehicleExemption>
            <xsl:value-of select="vehicleExemption"/>
          </vehicleExemption>
          <vehicleModel>
            <xsl:value-of select="vehicleModel"/>
          </vehicleModel>
          <vehicleType>
            <xsl:value-of select="vehicleType"/>
          </vehicleType>
        </VehicleDetailsVO>
      </xsl:for-each>
    </vehicleDetailsVOList>
</decreaseStickerVO>
  </xsl:template>
</xsl:stylesheet>

将其转换为下面的XML

XML:2

<?xml version="1.0" ?>
<decreaseStickerVO>
 <taxOfficeCod>04.20</taxOfficeCod>
<vehicleDetailsVOList>
<VehicleDetailsVO>
<chassis>878JHJH</chassis>
<circulationTax>6750</circulationTax>
<cylinderCapacity>De 1.801 c.c. a 2.400 c.c.</cylinderCapacity>
<registration>LD-11-11-KK</registration>
<registrationDate>2019-01-01</registrationDate>
<sealNum>K</sealNum>
<vehicleBrand>K</vehicleBrand>
<vehicleExemption>false</vehicleExemption>
<vehicleModel>K</vehicleModel>
<vehicleType>Ligeiros</vehicleType>
</VehicleDetailsVO>
<VehicleDetailsVO>
<chassis>878JHJHJ</chassis>
<circulationTax>2450</circulationTax>
<cylinderCapacity>De 126 c.c. a 450 c.c.</cylinderCapacity>
<registration>LDA-44-44</registration>
<registrationDate>2019-01-01</registrationDate>
<sealNum>K</sealNum>
<vehicleBrand>K</vehicleBrand>
<vehicleExemption>false</vehicleExemption>
<vehicleModel>K</vehicleModel>
<vehicleType>Motociclos</vehicleType>
</VehicleDetailsVO>
</vehicleDetailsVOList>
</decreaseStickerVO>

4.20
878JHJH
6750
De 1.801 c.c.a 2.400 c.c.c。
LD-11-11-KK
2019-01-01
K
K
假的
K
利盖罗斯
878JHJ
2450
De 126 c.c.a 450 c.c。
LDA-44-44
2019-01-01
K
K
假的
K
莫托西克洛斯
但结果如何呢

<decreaseStickerVO>
<taxOfficeCod>04.20</taxOfficeCod>
<vehicleDetailsVOList/>
</decreaseStickerVO>

4.20

请建议如何更改我的XSL模板以获得所需的结果

大多数结果为空的原因是:

<xsl:for-each select="VehicleDetailsVO">

但是,如果您希望保持现有XML中的所有内容不变,那么您可以简单地执行以下操作:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

甚至更短:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
    <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>


不是一个“标记”-它是一个XML声明。您的样式表显示了
省略xml声明=“是”
,因此您无法在输出中获得它。感谢您的回复。删除省略xml声明=“是”后。我仍然没有得到期望的输出。你能建议我的样式表还有哪些需要修改的地方吗?另外,请看复本的接受答案中的最后一条评论。它对序列化有很好的说明。
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
    <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>