help using XSLT in parsing nested xml trees

Discussion in 'XML' started by binary_sunset@yahoo.com, Mar 29, 2007.

  1. Guest

    Okay... so this may be all to obvious to all except myself, but I am
    having some difficulty with XML output from Adobe InDesign. Each
    separate article in my publication is tagged as an article, with a
    component tree, but the articles all appear in the XML output as child
    nodes of the previous article ala:

    <article>
    <title/>
    <date/>
    <body/>
    <article>
    <title/>
    <date/>
    <body/>
    <article>
    <title/>
    <date/>
    <body/>
    </article>
    </article>
    </article>

    The desired output from an XSLT would be something like three separate
    files (easy) with the structure:

    <article>
    <title/>
    <date/>
    <body/>
    </article>

    or at least:

    <article>
    <title/>
    <date/>
    <body/>
    </article>
    <article>
    <title/>
    <date/>
    <body/>
    </article>
    <article>
    <title/>
    <date/>
    <body/>
    </article>

    So how do I parse the output? It looks like a recursive process, as
    the number of nestings will vary with the number of articles in the
    signature, and by magazine. The idea of attaching an attribute
    <article id="n"> to each article occurred to me, but this changes the
    workflow somewhat, as ids were to be established in post-processing,
    rather than by hand.

    Thanks.
    Michael C.
    Light Technology Publishing
    , Mar 29, 2007
    #1
    1. Advertising

  2. Guest

    On Mar 30, 12:49 am, wrote:
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    > </article>
    > </article>
    >
    > The desired output from an XSLT would be something like
    > three separate files (easy) with the structure:


    Unless I'm much mistaken, XSLT1 cannot produce several
    result trees in one pass. For that matter, I'm not sure it
    can be done with EXSLT; and XSLT2 implementations are not
    that common yet.

    > or at least:
    >
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    >
    > So how do I parse the output? It looks like a recursive
    > process, as the number of nestings will vary with the
    > number of articles in the signature, and by magazine. The
    > idea of attaching an attribute <article id="n"> to each
    > article occurred to me, but this changes the workflow
    > somewhat, as ids were to be established in
    > post-processing, rather than by hand.


    Perhaps I'm missing something, but unnesting the structure
    described seems trivial enough to me:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <unnested-articles>
    <xsl:apply-templates select="//article"/>
    </unnested-articles>
    </xsl:template>
    <xsl:template match="article">
    <xsl:copy>
    <xsl:apply-templates
    select="@*|node()" mode="clone"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="@*|node()" mode="clone">
    <xsl:copy>
    <xsl:apply-templates
    select="@*|node()" mode="clone"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="article" mode="clone"/>
    </xsl:stylesheet>

    --
    Pavel Lepin
    , Mar 30, 2007
    #2
    1. Advertising

  3. Simon Brooke Guest

    in message <>,
    ('') wrote:

    > Okay... so this may be all to obvious to all except myself, but I am
    > having some difficulty with XML output from Adobe InDesign. Each
    > separate article in my publication is tagged as an article, with a
    > component tree, but the articles all appear in the XML output as child
    > nodes of the previous article ala:
    >
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    > </article>
    > </article>
    >
    > The desired output from an XSLT would be something like three separate
    > files (easy) with the structure:
    >
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    >
    > or at least:
    >
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    > <article>
    > <title/>
    > <date/>
    > <body/>
    > </article>
    >
    > So how do I parse the output? It looks like a recursive process, as
    > the number of nestings will vary with the number of articles in the
    > signature, and by magazine. The idea of attaching an attribute
    > <article id="n"> to each article occurred to me, but this changes the
    > workflow somewhat, as ids were to be established in post-processing,
    > rather than by hand.


    <xsl:template match="//article">

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/

    ;; Women are from Venus. Men are from Mars. Lusers are from Uranus.
    Simon Brooke, Mar 30, 2007
    #3
  4. Guest

    On Mar 30, 12:19 am, wrote:
    > On Mar 30, 12:49 am, wrote:
    >
    >
    >
    > > <article>
    > > <title/>
    > > <date/>
    > > <body/>
    > > <article>
    > > <title/>
    > > <date/>
    > > <body/>
    > > <article>
    > > <title/>
    > > <date/>
    > > <body/>
    > > </article>
    > > </article>
    > > </article>

    >
    > > The desired output from an XSLT would be something like
    > > three separate files (easy) with the structure:

    >
    > Unless I'm much mistaken, XSLT1 cannot produce several
    > result trees in one pass. For that matter, I'm not sure it
    > can be done with EXSLT; and XSLT2 implementations are not
    > that common yet.
    >
    >
    >
    > > or at least:

    >
    > > <article>
    > > <title/>
    > > <date/>
    > > <body/>
    > > </article>
    > > <article>
    > > <title/>
    > > <date/>
    > > <body/>
    > > </article>
    > > <article>
    > > <title/>
    > > <date/>
    > > <body/>
    > > </article>

    >
    > > So how do I parse the output? It looks like a recursive
    > > process, as the number of nestings will vary with the
    > > number of articles in the signature, and by magazine. The
    > > idea of attaching an attribute <article id="n"> to each
    > > article occurred to me, but this changes the workflow
    > > somewhat, as ids were to be established in
    > > post-processing, rather than by hand.

    >
    > Perhaps I'm missing something, but unnesting the structure
    > described seems trivial enough to me:
    >
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:template match="/">
    > <unnested-articles>
    > <xsl:apply-templates select="//article"/>
    > </unnested-articles>
    > </xsl:template>
    > <xsl:template match="article">
    > <xsl:copy>
    > <xsl:apply-templates
    > select="@*|node()" mode="clone"/>
    > </xsl:copy>
    > </xsl:template>
    > <xsl:template match="@*|node()" mode="clone">
    > <xsl:copy>
    > <xsl:apply-templates
    > select="@*|node()" mode="clone"/>
    > </xsl:copy>
    > </xsl:template>
    > <xsl:template match="article" mode="clone"/>
    > </xsl:stylesheet>
    >
    > --
    > Pavel Lepin


    Great! Thanks... This looks like it will work for now, and I'm going
    to pursue a dialogue with the folks at Adobe to see why the XML is
    being formatted like that in the first place, and if there is a way to
    configure it differently.

    Much appreciated.
    MC
    , Apr 2, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aleksi Kallio

    XSLT: Result trees in variables

    Aleksi Kallio, Aug 14, 2003, in forum: XML
    Replies:
    1
    Views:
    1,208
    Patryk Dworznik
    Aug 14, 2003
  2. David Svoboda

    Parsing multiple XML trees?

    David Svoboda, Dec 15, 2005, in forum: XML
    Replies:
    3
    Views:
    604
    Andrew Schorr
    Dec 16, 2005
  3. Ultrus
    Replies:
    3
    Views:
    364
    Stefan Behnel
    Jul 9, 2007
  4. jacob navia

    Binary search trees (AVL trees)

    jacob navia, Jan 3, 2010, in forum: C Programming
    Replies:
    34
    Views:
    1,391
    Dann Corbit
    Jan 8, 2010
  5. Michael Lesser

    Noob, html trees & parsing

    Michael Lesser, Jun 12, 2009, in forum: Ruby
    Replies:
    1
    Views:
    142
    Sanjay Sharma
    Jun 13, 2009
Loading...

Share This Page