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

Re: check for optional element

Subject: Re: check for optional element
From: Jarkko.Moilanen@xxxxxx
Date: Thu, 22 Jan 2004 12:10:33 +0200
xsl check element
Lainaus Nikolas Nehmer <Nikolas.Nehmer@xxxxxxxxxxx>:

< Hi,
<
< I want to check if an optional element is present in my XML document and
< if so I want to react to this fact. For example I have an optional
< element subsidiary in my Organesation.xml. If a subsidiary is present I
< want to create an additional column in my HTML table. How could I
< realise this test. The element-available() function does only apply to
< instruction elements I think?!
<
< Best regards,
<
< Nick

Source tree:

<?xml version="1.0"?>
<root>
<elements>
 <foobar>
 <subsidiary>is here</subsidiary>
 </foobar>

 <foobar>
 only foobar
 </foobar>
</elements>
</root>

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
 <new_root>
  <xsl:for-each select="root/elements/foobar">
   <xsl:if test="subsidiary">
     <xsl:copy-of select="."/>
   </xsl:if>
  </xsl:for-each>
</new_root>
</xsl:template>

</xsl:stylesheet>



result:

<?xml version="1.0" encoding="utf-8"?>
<new_root><foobar>
 <subsidiary>is here</subsidiary>
 </foobar>
</new_root>


***************************************************
* Jarkko Moilanen                                 *
* Dokumentoinnin kehittäjä                        *
* Profound XML technology Expert                  *
* DokuMentori Oy                                  *
* www.dokumentori.fi                              *
***************************************************

 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.