xsl-list
[Top] [All Lists]

Tag's depending on cousin element

2003-07-10 01:00:47
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



<Prev in Thread] Current Thread [Next in Thread>