473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help using XSLT in parsing nested xml trees

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 '07 #1
3 3851
On Mar 30, 12:49 am, binary_sun...@yahoo.com 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 '07 #2
in message <11*********************@n59g2000hsh.googlegroups. com>,
bi***********@yahoo.com ('bi***********@yahoo.com') 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">

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

;; Women are from Venus. Men are from Mars. Lusers are from Uranus.
Mar 30 '07 #3
On Mar 30, 12:19 am, p.le...@ctncorp.com wrote:
On Mar 30, 12:49 am, binary_sun...@yahoo.com 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 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
2
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now...
1
by: Miguel J. Jiménez | last post by:
Hi, I'm using OpenCMS and XML/XSLT to produce pages... The structure OpenCMS use for internal pages is something like this: <]> The desired effect I want to get is a page with "A title" in...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
3
by: SomeDude | last post by:
Lo group, During my quest for the "perfect" way for storing tree-structures it quickly became clear that all of the available SQL-solutions have their own peculiar weaknesses (scalability, slow...
5
by: dennis | last post by:
Hi, First of all, hi to you all. I'm working on a Delphi project wich is becoming near it's deadline. I have a very simple XSLT question wich i hope one of you folks can help me with? The...
5
by: gamehack | last post by:
Hi all, I was thinking about parsing equations but I can't think of any generic approach. Basically I have a struct called math_term which is something like: struct math_term { char sign; int...
6
by: Lenny Wintfeld | last post by:
Hi I'm attempting additions/changes to a Java program that (among other things) uses XSLT to transform a large (96 Mb) XML file. It runs fine on small XML files but generates OutOfMemory...
2
by: trash.muell | last post by:
Hi, I am struggling with an XSLT task and need a hint: I have a complex XML file but want to only output some sub-trees of the XML structure. My XSLT script is always printing the information of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.