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

Tag's depending on cousin element

Subject: Tag's depending on cousin element
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Thu, 10 Jul 2003 08:00:47 +0000
choose tag
Hi all!

I don't know if this title is at all descriptive, but here are my problems:

I have something that cn be like this, with no control over the form:

<lv>
<state><secret/><important/></state>
<declaration> Some text here </declaration>
</lv>

Now, I wan't the output to be something like
<lv>
<secret><important> Some text here </important></secret>
</lv>

Not all declarations are secret, nor all important.
So I can have some <state></state> or <state><important/</state> or some such.


My current solution (on paper) is something like:

...
<xsl:template match="lv/declaration">
 <xsl:call-template name="state"/>
</xsl:template>

<xsl:template name="state">
 <xsl:choose>
   <xsl:when test="../state/secret">
     <xsl:choose>
       <xsl:when test="../state/important">
         <secret><important><xsl:value-of select="."/></important></secret>
       </xsl:when>
       <xsl:otherwise>
         <secret><xsl:value-of select="."/></secret>
	</xsl:otherwise>
     </xsl:choose>
   </xsl:when>
   <xsl:otherwise>
     <xsl:choose>
       <xsl:when test="../state/important">
         <important><xsl:value-of select="."/></important>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="."/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>
...


First, I don't know if the test will function at all since they are empty elements.
If they don't work, how do I test for these?
If they work, how would I (in future) be able to test if the element is empty?
(I have Michael Kay's book 2nd edition, so if it is described in this book, just point me in the right direction, please).


Second, I don't like my solution at all. It is not verey generic, and for each new state introduced (I have no control over this), my "state" template doubles in size.

Is there some smarter way of doing this?
A more elaborate answer than "yes" or "no" will be appreciated :)

Thanks!

Ragulf Pickaxe :)

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



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.