xsl-list
[Top] [All Lists]

Re: [xsl] Ways to Identify & Process Same name XML elements differently based on location in XML tree?

2017-10-25 07:52:34
On Wed, Oct 25, 2017 at 12:34:55PM -0000, Alex S 
as(_dot_)signup(_at_)hotmail(_dot_)com
scripsit:
 Some elements such as: <string> <array> <dict> appear repeatedly at
 multiple levels in this SB XML format, But they mean different things
 based on where they are located; mean different things at different
 locations, depths or parent/ ascendent

 What are the different ways I can tackle processing these elements
 and fix & improve my <xsl templates>?

There's a general XSLT 2.0-and-greater pattern, "chained processing",
where you can put a document node in a variable so you can pass the
result of one processing pass to the next using variables:

<xsl:variable name="pass1">
    <xsl:apply-templates mode="preprocess"/>
</xsl:variable>
<xsl:apply-templates select="pass1"/>

This generalizes to arbitrarily many variables (presuming the documents
aren't large enough to give you memory issues at however many variables
you need) and I find it's a good way to keep different bits of the
processing logic distinct in the code and thus easier to debug.

So nothing wrong with doing what you're already doing and using a
pre-processing pass to give the elements distinct names depending on
position and then processing on that basis.

-- Graydon
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>