Loading ...
Sorry, an error occurred while loading the content.

Transformation Issue

Expand Messages
  • UlyLee
    I have a transformation issue and concerns xslt 2.0 (i hope this is not a off topic)... i have 1 source document and want to transform the document into
    Message 1 of 1 , Sep 7, 2005
    • 0 Attachment
      I have a transformation issue and concerns xslt 2.0 (i hope this is
      not a off topic)... i have 1 source document and want to transform the
      document into multiple outputs thats why i'm using xslt 2.0 because it
      can produce multiple outputs. i have this sample source that i work
      on:

      <aaa>
      <bbb>
      <ccc variant="doc1">
      <ddd>text</ddd>
      </ccc>
      <ccc variant="doc2">
      <ddd>text</ddd>
      </ccc>
      <ccc variant="doc1">
      <ddd>text</ddd>
      </ccc>
      <ccc variant="doc2">
      <ddd>text</ddd>
      </ccc>
      </bbb>
      </aaa>

      and my xslt code:

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

      <xsl:template match="/">
      <xsl:for-each-group select="//*" group-by="@variant">
      <xsl:result-document href="{@variant}.xml">

      <xsl:for-each select="current-group()">
      <xsl:element name="{name(.)}">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
      </xsl:element>
      </xsl:for-each>

      </xsl:result-document>
      </xsl:for-each-group>
      </xsl:template>

      <xsl:template match="*">
      <xsl:element name="{name(.)}">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
      </xsl:element>
      </xsl:template>
      </xsl:stylesheet>

      and my output is
      doc1.xml:
      <ccc variant="doc1">
      <ddd>text</ddd>
      </ccc>
      <ccc variant="doc1">
      <ddd>text</ddd>
      </ccc>

      doc2.xml
      <ccc variant="doc2">
      <ddd>text</ddd>
      </ccc>
      <ccc variant="doc2">
      <ddd>text</ddd>
      </ccc>

      my problem is, i want to output the ancestors of the element <ccc> to
      maintain the same structure of that of the source xml. i tried adding
      <xsl:copy-of select="ancestor::node()"/> before the
      <xsl:result-document> but i have the wrong output. can anyone there
      give me an idea on how to work around this problem???

      thanks
      UlyLee
    Your message has been successfully submitted and would be delivered to recipients shortly.