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

Re: treating variables like nodes - testing for existe

Subject: Re: treating variables like nodes - testing for existence
From: Esha Datta <edatta@xxxxxxxx>
Date: Tue, 02 May 2006 07:47:42 -0600
esha datta
Thanks Dimitre, that worked. I had spent time researching on RTFs though, just couldn't figure this out.

Esha
At 11:10 PM 5/1/2006, you wrote:


Date: Mon, 1 May 2006 15:48:05 -0700
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Subject: Re:  treating variables like nodes - testing for existence
Message-ID: <1563432b0605011548s456e8ee3gf62e2e454bfcf19b@xxxxxxxxxxxxxx>

Result Tree Fragment is a fundamental concept in XSLT 1.0. Do
read/search on this subject.

As the time does not permit, below is a quick fix to your problem:

Instead of:

> <xsl:with-param name=3D"test" select=3D"$test"/>

use:
                       <xsl:with-param name=3D"test" select=3D"string($test=
)"/>

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.

On 5/1/06, Esha Datta <edatta@xxxxxxxx> wrote:
>
> >hi all,
> >
> >I am trying to write code that will treat a variable as a node.  If
> >a variable is empty, I want the stylesheet to think it's
> >non-existent rather than existing, but empty. For example, I am
> >trying to parse out a string from element, foo. If the value exists,
> >I want it to print <test>value of foo</test>.  If it doesn't exist,
> >I don't want it to print out anything. Right now, it still prints
> >out the tags because the variable exists but is empty at this point.
> >Is there any way to check for variable existence like one can with
> >nodes?  So if the variable is empty after parsing out the element, I
> >want the stylesheet to think that there is no variable. The larger
> >issue is that we have templates that process nodes and print output
> >if they exist or if the nodes exist, but there is no value.  There
> >are some nodes to which we do some processing or parsing where we
> >need variables(like with foo in the example below), when we pass
> >these variables to templates, I want these templates to treat these
> >variables like nodes.  Thanks for your help!
> >
> >
> >stylesheet:
> ><xsl:stylesheet version=3D"1.0"
> >xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> >xmlns:fo=3D"http://www.w3.org/1999/XSL/Format">
> >
> ><xsl:template match=3D"/">
> ><xml>
> ><xsl:for-each select=3D"//foo">
> >         <xsl:variable name=3D"test">
> >                 <xsl:if test=3D"contains(.,'em')">
> >                 <xsl:value-of select=3D"substring-after(.,'em: ')"/></x=
sl:if>
> >         </xsl:variable>
> >         <xsl:call-template name=3D"runTest">
> >                 <xsl:with-param name=3D"test" select=3D"$test"/>
> >         </xsl:call-template>
> ></xsl:for-each>
> ></xml>
> ></xsl:template>
> >
> ><xsl:template name=3D"runTest">
> >         <xsl:param name=3D"test"/>
> >
> >         <xsl:if test=3D"$test">
> >             <test>
> >                 <xsl:value-of select=3D"$test"/>
> >           </test>
> >         </xsl:if>
> ></xsl:template>
> ></xsl:stylesheet>
> >
> >xml file:
> ><xml>
> ><foo>bar1</foo>
> ><foo>bar;em: bar2</foo>
> ></xml>
> >
> >This is the result I get:
> ><xml xmlns:fo=3D"http://www.w3.org/1999/XSL/Format">
> >         <test />
> >         <test>bar2</test>
> ></xml>
> >
> >
> >
> >Esha Datta
>
>
>
> >Los Alamos National Laboratory Research Library

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.