XSL转换拆分标签-添加到父级和子级

时间:2019-12-03 00:57:47

标签: xml xslt xpath

我的响应XML如下

<?xml version="1.0" encoding="UTF-8"?>
<taxCalculation xmlns="http://www.sabrix.com/services/taxcalculationservice/2011-09-01" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <OUTDATA version="G">
    <INVOICE>
      <INVOICE_NUMBER>GOOGLE.MN.347917</INVOICE_NUMBER>
      <LINE ID="1">
        <DESCRIPTION>ITEM-MN-10-ROL21-ROLLER DRIVE. PN. M23279</DESCRIPTION>
        <GROSS_AMOUNT>12723.90</GROSS_AMOUNT>
        <LINE_NUMBER>1</LINE_NUMBER>
        <TOTAL_TAX_AMOUNT>1021.09</TOTAL_TAX_AMOUNT>     
        <TAX_SUMMARY>
          <TAXABLE_BASIS>12723.90</TAXABLE_BASIS>
          <NON_TAXABLE_BASIS>0.00</NON_TAXABLE_BASIS>
          <EXEMPT_AMOUNT>0.00</EXEMPT_AMOUNT>
          <TAX_RATE>0.08025</TAX_RATE>
          <EFFECTIVE_TAX_RATE>0.0802497662</EFFECTIVE_TAX_RATE>
        </TAX_SUMMARY>
      </LINE>
      <COMPANY_ROLE>B</COMPANY_ROLE>
      <VENDOR_NAME>Google Solution Providers Inc</VENDOR_NAME>
      <VENDOR_NUMBER>235478</VENDOR_NUMBER>
    </INVOICE>
  </OUTDATA>
</taxCalculation>

我想按如下方式转换此xml。我正在努力使用xsl将标签INVOICE_NUMBER转换为3个不同的标签。感谢您的帮助

<?xml version="1.0" encoding="utf-8"?><max:GetResponse creationDateTime="2019-10-26T12:22:00-04:00" xmlns:max="http://www.ibm.com/maximo">
  <max:GetResponseSet>
    <max:PR>
      <max:ORGID>GOOGLE</max:ORGID>
      <max:SITEID>MN</max:SITEID>
      <max:PRNUM>347917</max:PRNUM>
      <max:PRLINE>
        <max:PRLINENUM>1</max:PRLINENUM>
        <max:TAX1 changed="true">1021.09</max:TAX1>
        <max:GONETAXRATE changed="true">0.08025</max:GONETAXRATE>
        <max:ORGID>GOOGLE</max:ORGID>
        <max:SITEID>MN</max:SITEID>
        <max:PRNUM>347917</max:PRNUM>
      </max:PRLINE>
    </max:PR>
  </max:GetResponseSet>
</max:GetResponse>

2 个答案:

答案 0 :(得分:0)

在XSLT版本中。 1您可以使用substring-aftersubstring-before,例如:

<max:ORGID>
    <xsl:value-of select="substring-before(., '.')"/>
</max:ORGID>
<max:SITEID>
    <xsl:value-of select="substring-before(substring-after(., '.'), '.')"/>
</max:SITEID>

答案 1 :(得分:0)

非常感谢@Kirill Polishchuk。我如下解决了这个问题

<max:ORGID><xsl:value-of select="substring-before($invoiceNumber, '.')"/></max:ORGID>
<max:SITEID><xsl:value-of select="substring-before(substring-after($invoiceNumber, '.'), '.')"/></max:SITEID>
<max:PRNUM><xsl:value-of select="substring-after(substring-after($invoiceNumber, '.'), '.')"/></max:PRNUM>