XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Steve OwensSubject: Brain Teaser
Author: Steve Owens
Date: 05 Sep 2007 10:32 AM
I have a problem in XSLT that I simply do not know how to solve. Perhaps someone smarter than me can show their stuff.

Suppose you have a document such as the following:

<root>
<section type="foo">
<a>Text 1</a>
<a type="bar">Mixed Content
<b type="foo">Text 2</b>
<b>Mixed Content
<c>Text 3</c>
<c type="bar">Text 4</c>
</b>
</a>
</section>
</root>

Further suppose that the schema allows section tags to contain any single letter tag a-z. Also any single letter tag a-z may contain any combination of single letter tags a-z. All single letter tags support mixed content as well.

How is it possible using XSLT to do convert the document to one such as the following.

<root>
<type name="foo">
<section type="foo" tag-id="001">
<a tag-id="002">Text 1</a>
</section>
</type>
<type name="bar">
<section tag-cont="001">
<a tag-cont="002">
<b tag-id="003">Text 2</b>
<b tag-id="004">Mixed Content
<c>Text 3</c>
</b>
</a>
</section>
</type>
<type name="foo">
<section tag-cont="001">
<a tag-cont="002">
<b tag-cont="004">
<c tag-id="005">Text 4</c>
</b>
</a>
</section>
</type>
</root>

The idea is that whenever a new type attribute is encountered on a tag, we close the close everything up to a certain stopping point such as the child of root in this case, and then we re-open duplicates of everything, and continue on with the processing.

I think it is fairly trivial to write a transform that goes from the latter to the former, but I can think of no way to go from the former to the latter.

Anyone out there up for a challenge?

Postnext
James DurningSubject: Brain Teaser
Author: James Durning
Date: 05 Sep 2007 12:07 PM
Originally Posted: 05 Sep 2007 11:58 AM
To be honest, since this uses xml merely as a linear processing language, I would use a linear programming language to do this. Eg SAX in Java would be a much better tool.

If you're stuck with XSLT, I'm pretty sure you would need the use of node-set variables, which requires common extension functions or XSLT 2.0

Another possible way to do this is to have 26 variables for each of the 26 tags, but the code gets very, very ugly.

The way I could see doing this at the moment would be something like:
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="carry" select="$carry">
</xsl:apply-templates>

Postnext
Tony LavinioSubject: Brain Teaser
Author: Tony Lavinio
Date: 05 Sep 2007 01:14 PM
General XSLT questions are best asked on the xsl-list run by
Mulberry Technologies. It draws from a much broader pool of
experts as it is not limited to any one product.

Posttop
Steve OwensSubject: Brain Teaser
Author: Steve Owens
Date: 05 Sep 2007 02:32 PM
Thank you for that advice. I appreciate your telling me about that site.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.