Recursion of tags in one tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cedric Vonck

    Recursion of tags in one tag

    Hello everybody,

    I have a question about xml / xsl(t).

    I need to transform a following kind of xml to editable file (format
    does not matter).

    The xml file look like this:

    <...> Root
    <tag>
    <subtag1>.... .</subtag1>
    <subtag2>.... .</subtag2>
    ....
    ....
    <subtag1>.... .</subtag1>
    <subtag2>.... .</subtag2>
    </tag>
    </...> End Root

    Subtag1 & Subtag2 can repeat themselves n-times.
    I know that this is xml is wellformed but not wellstructured.

    The ideal solution should be:

    <...> Root
    <tag>
    <detail>
    <subtag1>.... .</subtag1>
    <subtag2>.... .</subtag2>
    </detail>
    <detail>
    <subtag1>.... .</subtag1>
    <subtag2>.... .</subtag2>
    </detail>
    </tag>
    </...> End Root

    If the xml should like this (in the ideal case) I could get the
    conversion to work in no time.

    Any suggestions how I could write a correct xsl(t) for the first
    example???

    Thank you
  • Joris Gillis

    #2
    Re: Recursion of tags in one tag

    Tempore 15:25:40, die Thursday 10 February 2005 AD, hinc in foro {comp.text.xml} scripsit Cedric Vonck <vanderhoeven@p ing.be>:

    [color=blue]
    > Subtag1 & Subtag2 can repeat themselves n-times.
    > I know that this is xml is wellformed but not wellstructured.
    >
    > The ideal solution should be:
    >
    > <...> Root
    > <tag>
    > <detail>
    > <subtag1>.... .</subtag1>
    > <subtag2>.... .</subtag2>
    > </detail>
    > <detail>
    > <subtag1>.... .</subtag1>
    > <subtag2>.... .</subtag2>
    > </detail>
    > </tag>
    > </...> End Root
    >
    > If the xml should like this (in the ideal case) I could get the
    > conversion to work in no time.
    >
    > Any suggestions how I could write a correct xsl(t) for the first
    > example???[/color]
    Hi,

    I'm not really sure if this is really what you asked for, but here's an xslt that converts the first document into the second:

    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="node() | @*">
    <xsl:copy>
    <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="*[subtag1]">
    <xsl:copy>
    <xsl:apply-templates select="node()[not(self::subta g2)] | @*"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="subtag1" >
    <details>
    <xsl:copy-of select=". | following-sibling::subtag 2[1]"/>
    </details>
    </xsl:template>

    </xsl:stylesheet>


    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
    Vincit omnia simplicitas
    Keep it simple

    Comment

    • Cedric Vonck

      #3
      Re: Recursion of tags in one tag

      > <xsl:styleshe et version="1.0"[color=blue]
      > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
      > <xsl:output method="xml" indent="yes"/>
      >
      > <xsl:template match="node() | @*">
      > <xsl:copy>
      > <xsl:apply-templates select="node() | @*"/>
      > </xsl:copy>
      > </xsl:template>
      >
      > <xsl:template match="*[subtag1]">
      > <xsl:copy>
      > <xsl:apply-templates select="node()[not(self::subta g2)] | @*"/>
      > </xsl:copy>
      > </xsl:template>
      >
      > <xsl:template match="subtag1" >
      > <details>
      > <xsl:copy-of select=". | following-sibling::subtag 2[1]"/>
      > </details>
      > </xsl:template>
      >
      > </xsl:stylesheet>
      >
      >
      > regards,[/color]

      Thank you for your answer, but I should have made my post more
      clearer.
      The second example with the (<detail>) tag is no problem for me.
      It is the first one that poses problems.

      So if possible, could anyone explain to me how I have to write a
      decent xsl(t) for it??

      Thx

      Comment

      Working...