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

Re: Design question

Subject: Re: Design question
From: Antonio Fiol <fiol@xxxxxxxxxx>
Date: Wed, 10 Jul 2002 09:49:38 +0200
xsl when test type
You could do what you say, but why not doing the following:

<xsl:template match="test[@type='positive']">
<da:Positive name="@name">
<xsl:for-each select="param">
<xsl:choose>
<xsl:when test="starts-with(@name,'p')">
<xsl:attribute name="{@name}"><xsl:value-of select="."/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:element name="da:Date">
<xsl:attribute name="number"><xsl:value-of select="substring(@name,4)"/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</da:Positive>
</xsl:template>


Beware: untested.


Antonio


Jay Burgess wrote:

I'm attempting to use XSL to transform XML to XML. The problem is that some child elements in the original XML are "attributes" of the new XML element, whereas other child "elements" are actually new child elements. That is:

BEFORE:
    <test type="positive" name="Test 1">
        <param name="p1">123</param>
        <param name="date1">July 9</param>
        <param name="p2">false</param>
    </test>

AFTER:
    <da:Positive name="Test 1" p1="123" p2="false">
       <da:Date number="1" value="July 9"/>
    </da:Positive>

(Notice that p1 and p2 become attributes of the new element, but date1 becomes a new child element.)

From what I can tell, I need to accomplish the equivalent of the following, but haven't been able to come up with the way to do it:

(1) Iterate through all original <param>s. For each <param> that will become an attribute, do <xsl:attribute>. For each <param> that will become a child element, store it off to the side in a node set of some sort.

(2) When the iteration is complete, iterate through the node set built in (1), and do <xsl:element> on each.

Is this the right way to solve this problem? If so, can someone provide some more detail, as nothing I've tried has worked. Or, is there a better way?

Thanks in advance.

Jay

-- Jay Burgess [jburgess@xxxxxxxxxxx]
   Digital Archaeology Corporation
   (913) 438-9444 x154


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



.






XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


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.