0

需要帮忙!刚从 xslt 开始,不知道如何在我的情况下进行转换,thanx 事先

源 XML

  <?xml version="1.0" encoding="UTF-8"?>
<body xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" ...>
  <tns:getRealEstateObjects>
    <RequestElement>     
      <IdNumnet>30361100000000000034</IdNumnet>     
      <IdSelectFromDate></IdSelectFromDate>
    </RequestElement>
  </tns:getRealEstateObjects>
</body>

目标 XML

<?xml version="1.0" encoding="UTF-8"?>
<result  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sa="http://www.ibm.com/xmlns/prod/websphere/j2ca/sap">
  <IdNumnet>30361100000000000034</IdNumnet>
  </result>

生成了我应该编辑的 xslt

  <xsl:output method="xml" encoding="UTF-8" indent="yes" xalan:indent-amount="2"/>
  <xsl:strip-space elements="*"/>

  <!-- The rule represents a custom mapping: "IdSelectFromDate" to "IdSelectFromDate". -->
  <xsl:template name="IdSelectFromDateToIdSelectFromDate">
    <xsl:param name="IdSelectFromDate"/>
    <!-- ADD CUSTOM CODE HERE. -->
  </xsl:template>
</xsl:stylesheet>
4

1 回答 1

0

我不知道这个话题是否仍然活跃,但你可以尝试关注

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

 <xsl:template match="/">
    <result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sa="http://www.ibm.com/xmlns/prod/websphere/j2ca/sap">
        <xsl:apply-templates select="body/getRealEstateObjects/RequestElement" />
    </result>
 </xsl:template>

    <xsl:template match="body/getRealEstateObjects/RequestElement">
        <xsl:copy-of select="IdNumnet" />
        <xsl:call-template name="IdSelectFromDateToIdSelectFromDate">
            <xsl:with-param name="IdSelectFromDate" select="IdSelectFromDate" />
        </xsl:call-template>    

    </xsl:template>

  <!-- The rule represents a custom mapping: "IdSelectFromDate" to "IdSelectFromDate". -->
  <xsl:template name="IdSelectFromDateToIdSelectFromDate">
    <xsl:param name="IdSelectFromDate"/>
    <xsl:choose>
        <xsl:when test="normalize-space($IdSelectFromDate) = ''">
            <xsl:comment>IdSelectFromDate is empty - do nothing</xsl:comment>
        </xsl:when>
        <xsl:otherwise>
            <!-- Do something with IdSelectFromDate -->
            <xsl:copy-of select="$IdSelectFromDate" />
        </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

我只是做了一些简化,以免打扰命名空间等,但原则应该保持不变。

于 2013-07-09T06:17:14.837 回答