Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > help using XSLT in parsing nested xml trees

Reply
Thread Tools

help using XSLT in parsing nested xml trees

 
 
binary_sunset@yahoo.com
Guest
Posts: n/a
 
      03-29-2007
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

 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      03-30-2007
On Mar 30, 12:49 am, (E-Mail Removed) 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"
xmlnssl="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

 
Reply With Quote
 
 
 
 
Simon Brooke
Guest
Posts: n/a
 
      03-30-2007
in message <(E-Mail Removed). com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) ('(E-Mail Removed)') 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">

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

;; Women are from Venus. Men are from Mars. Lusers are from Uranus.
 
Reply With Quote
 
binary_sunset@yahoo.com
Guest
Posts: n/a
 
      04-02-2007
On Mar 30, 12:19 am, (E-Mail Removed) wrote:
> On Mar 30, 12:49 am, (E-Mail Removed) 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"
> xmlnssl="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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binary search trees (AVL trees) jacob navia C Programming 34 01-08-2010 07:27 PM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Parsing multiple XML trees? David Svoboda XML 3 12-16-2005 02:58 PM
[XML::XSLT] empty result while parsing xml file PL Perl Misc 2 12-14-2004 10:24 PM



Advertisments