[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Move a section to different part of the XML tree based

Subject: Move a section to different part of the XML tree based on child values
From: Rob Newman <rlnewman@xxxxxxxx>
Date: Mon, 21 Jul 2008 16:25:30 -0700
 Move a section to different part of the XML tree based
Hi there XML gurus,

I have an XML file with the contents:

output.xml

<Folder>
    <name>Station List</name>
    <Placemark>
       <name>PFO</name>
       <visibility>1</visibility>
    </Placemark>
    <Placemark>
       <name>MONP2</name>
       <visibility>1</visibility>
    </Placemark>
    <Placemark>
       <name>MONP</name>
       <visibility>0</visibility>
    </Placemark>
    <Placemark>
       <name>POTR</name>
       <visibility>0</visibility>
    </Placemark>
</Folder>

Based on the value of the visibility tag, I would like to rearrange the output to be split into two sections - 'Visible Stations' and 'Invisible Stations':

output_reordered.xml

<Folder>
    <Section>
        <name>Visible Stations</name>
        <Placemark>
           <name>PFO</name>
           <visibility>1</visibility>
        </Placemark>
        <Placemark>
           <name>MONP2</name>
           <visibility>1</visibility>
        </Placemark>
    </Section>
    <Section>
        <name>Invisible Stations</name>
        <Placemark>
           <name>MONP</name>
           <visibility>0</visibility>
        </Placemark>
        <Placemark>
           <name>POTR</name>
           <visibility>0</visibility>
        </Placemark>
    </Section>
</Folder>

I have a template that matches on the Folder tag, and I get the value of visibility into a variable.

convert.xsl

<xsl:template match="/">
<Folder>
<!-- How do I enter and populate the Sections here? -->
<xsl:template match="Folder/Placemark">
<xsl:variable name="thisVisible"><xsl:value-of select="visibility" /></xsl:variable>


<!-- Some sort of if/else statement that then moves the Placemark to the correct location? -->

<Placemark>
<name><xsl:value-of select="name" /></name>
<visibility><xsl:value-of select="visibility" /></ visibility>
</Placemark>
</xsl:template>
</Folder>
</xsl:template>


How can I ensure that if the visibility tag is set to 1 it gets inserted into the result tree in the right section (in the Folder named Visible Stations) and if the tag is set to 0 it gets inserted into the result tree in the Invisible Stations tag? I assume I need to create the Sections by hand, but then moving the Placemark sections into one of the Sections is the part I am stuck on.

Thanks in advance,
- Rob

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.