Search code examples
xmlxsltxsd

Transform flat array


im stuck with my XSLT script. This is my input:

<?xml version='1.0' encoding='UTF-8'?>
<root>
    <ID>12345563</ID>
    <ID>12345564</ID>
</root>

what i tryed was this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <batchParts>
          <xsl:for-each select="root">
              <Test><xsl:value-of select="." /></Test>
          </xsl:for-each>
      </batchParts>
    </xsl:template>
</xsl:stylesheet>

Thats my current ouput:

<?xml version="1.0" encoding="UTF-8"?><batchParts><Test>
    12345563
    12345564
</Test></batchParts>

what i want to accomplish is this:

<?xml version="1.0" encoding="UTF-8"?><batchParts><Test>
    <Test>12345563</Test>
    <Test>12345564</Test>
</batchParts>

what am i doing wrong?


Solution

  • I think you want this instead :

    <?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" indent="yes"/>
        <xsl:template match="/">
          <batchParts>
              <xsl:for-each select="root/ID">
                  <Test><xsl:value-of select="." /></Test>
              </xsl:for-each>
          </batchParts>
        </xsl:template>
    </xsl:stylesheet>