XSL for XML

Questions about XML that are not covered by the other forums should go here.
solidden
Posts: 1
Joined: Sat Jun 04, 2022 2:18 am

XSL for XML

Post by solidden »

Hello,

i have below xml, having difficulty in generating xsl for this. I would like to separate this into two files based on testbook-id. I am able to list them, but not sure how can I separate them into two files.
Any help would be greatly appreciated.


here is the sample xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<testbooks xmlns="SOME_NS">

  <testbook>
    <header testbook-id="ca-cad-list">
      <currency>CAD</currency>
      <online-flag>true</online-flag>
    </header>
    <price-tables>
      <price-table product-id="035:M:1:">
        <online-from>2022-06-02T00:00:00.000Z</online-from>
        <online-to>9999-12-31T23:59:59.000Z</online-to>
        <amount quantity="1">90.00 </amount>
      </price-table>
    </price-tables>
  </testbook>

  <testbook>
    <header testbook-id="ca-cad-sale">
      <currency>CAD</currency>
      <online-flag>true</online-flag>
    </header>
    <price-tables>
      <price-table product-id="035:M:1:">
        <online-from>2022-06-02T00:00:00.000Z</online-from>
        <online-to>9999-12-31T23:59:59.000Z</online-to>
        <amount quantity="1">85</amount>
      </price-table>
    </price-tables>
  </testbook>
  
</testbooks>
Radu
Posts: 9048
Joined: Fri Jul 09, 2004 5:18 pm

Re: XSL for XML

Post by Radu »

Hi,

You can use the XSLT result-document function to create multiple files on disk, something like this for example:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs"
  version="2.0">
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*:testbook">
    <xsl:result-document href="{*:header/@testbook-id}">
      <xsl:apply-templates/>
    </xsl:result-document>
  </xsl:template>
</xsl:stylesheet>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply