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

RE: Tag's depending on cousin element

Subject: RE: Tag's depending on cousin element
From: Jarno.Elovirta@xxxxxxxxx
Date: Thu, 10 Jul 2003 11:33:08 +0300
xsl copy depending elements
Hi,

> First, I don't know if the test will function at all since 
> they are empty 
> elements.

They do. See <http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose> and <http://www.w3.org/TR/xpath#section-Boolean-Functions>.

> If they work, how would I (in future) be able to test if the 
> element is 
> empty?

Try to select it's children. "foo/node()" for any child, "foo/*" for elements children, and so forth.

> 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 :)

For example

  <xsl:template match="lv">
    <xsl:copy>
      <xsl:choose>
        <xsl:when test="state/*">
          <xsl:apply-templates select="state/*[1]" mode="x"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="declaration"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*" mode="x">
    <xsl:copy>
      <xsl:choose>
        <xsl:when test="following-sibling::*">
          <xsl:apply-templates select="following-sibling::*[1]" mode="x"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="../../declaration"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>

or

  <xsl:template match="lv">
    <xsl:copy>
      <xsl:apply-templates select="(state/* | declaration)[1]" mode="x"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*" mode="x">
    <xsl:copy>
      <xsl:apply-templates select="following::*[1]" mode="x"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="declaration" mode="x">
    <xsl:value-of select="."/>
  </xsl:template>

Cheers,

Jarno - C-Drone Defect: Psycho2vii


 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.