Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] treating variables like nodes - testing for existence

From: "Dimitre Novatchev" <dnovatchev@--------->
To:
Date: 5/1/2006 10:56:00 PM
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="test" select="$test"/>



use:
                      <xsl:with-param name="test" select="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="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>xmlns:fo="http://www.w3.org/1999/XSL/Format">
>
><xsl:template match="/">
><xml>
><xsl:for-each select="//foo">
>         <xsl:variable name="test">
>                 <xsl:if test="contains(.,'em')">
>                 <xsl:value-of select="substring-after(.,'em:
')"/></xsl:if>
>         </xsl:variable>
>         <xsl:call-template name="runTest">
>                 <xsl:with-param name="test" select="$test"/>
>         </xsl:call-template>
></xsl:for-each>
></xml>
></xsl:template>
>
><xsl:template name="runTest">
>         <xsl:param name="test"/>
>
>         <xsl:if test="$test">
>             <test>
>                 <xsl:value-of select="$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="http://www.w3.org/1999/XSL/Format">
>         <test />
>         <test>bar2</test>
></xml>
>
>
>
>Esha Datta





>Los Alamos National Laboratory Research Library


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent