[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: check for optional 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|