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

RE: [xslt] xslt problem

Subject: RE: [xslt] xslt problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 19 Mar 2009 09:00:37 -0000
RE:  [xslt] xslt problem
Not the most imaginative title for a post. 

> 
> <example>
>     <someNode>
>             <value>asas</value>
>             <name>asas</name>
>             <space>12</space>
>     </someNode>
>     <interestingNode>
>             <con>someString</con>
>             <follow>
>                     <node1>1</node1>
>                     <node2>2</node2>
>                     <node3>3</node3>
>                     <node4>4</node4>
>             </follow>
>             <space>5</space>
>     </interestingNode>
> </example>
> 
> 
> Now i want to transform it to:
> 
> <example>
>     <someNode>
>             <value>asas</value>
>             <name>asas</name>
>             <space>12</space>
>     </someNode>
>     <interestingNode>
>             <con>someString</con>
>             <follow>
>                     <return>0</return>
>             </follow>
>             <space>5</space>
>     </interestingNode>
> 
>     <node1 space="5">1</node1>
>     <node2 space="5">2</node2>
>     <node3 space="5">3</node3>
>     <node4 space="5">4</node4>
> </example>
> 
> 
> The changes are:
> - when interestingNode is found, we check the con value
> - if con value conforms someString, then we make 
> transformation of this part by:
>     - evrything in follow node is moved outside interestingNode
>     - follow node gets one child return
>     - all nodes moved outside get an attribute space with 
> value specified in original node
> 

That seems to be a rule you can translate directly into XSLT:

<xsl:template match="interestingNode[con='someString']">
  <xsl:copy>
    <xsl:copy-of select="con"/>
    <follow><return>0</return></follow>
    <xsl:copy-of select="space"/>
  </xsl:copy>
  <xsl:variable name="space" select="space"/>
  <xsl:for-each select="follow/*">
    <xsl:copy>
      <xsl:attribute name="space" select="$space"/>
      <xsl:copy-of select="child::node()"/>
    </xsl:copy>
  </xsl:for-each>
</xsl:template>

Michael Kay
http://www.saxonica.com/

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.