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

Re: Re: dynamic xpath from variable evaluate function

Subject: Re: Re: dynamic xpath from variable evaluate function is failing
From: M Balaji <msbalaji82@xxxxxxxxx>
Date: Mon, 22 Oct 2012 13:38:50 +0530
Re:  Re: dynamic xpath from variable evaluate function
Thanks Michael,

On Mon, Oct 22, 2012 at 1:31 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> If you evaluate
>
>
> <b test="(y=Unix) and (y=Solaris)">content</b>
>
> as an XPath expression the result will probably be false, because it means
>
> <b test="(child::y=child::Unix) and (child::y=child::Solaris)">content</b>
>
> and comparing two empty sequences using "=" gives false.

Yeah, that is why I'm adding text

<xsl:variable name="conlist"><s><xsl:for-each
>> select="document('config.xml')// condition"><xsl:element
>> name="{@name}">test</xsl:element><xsl:element
>> name="{@value}">test</xsl:element></xsl:for-each></s></xsl:variable>

>
> However, as far as I can tell the string value of conlist will be empty, so
> the expression you are constructing is
>
> $//[(y=Unix) and (y=Solaris)]

$conlist//s[(y=Unix) and (y=Solaris)] in $t

>
> which would be a syntax error.
>
> You would make your life a lot easier if the expressions in the conditions
> file used XPath syntax, that is, quotes around the values.
>
> Michael Kay
> Saxonica
>
>
>
>
>
> On 22/10/2012 06:41, M Balaji wrote:
>>
>> I need to construct the dynamic XPATH predicate from the input XML. I
>> tried
>> with evaluate function, but  its not converting the String to XPATH
>> predicate. Can any one let me know how can I achieve this?
>>
>>   Input: test.xml
>>
>> <a>
>>
>> <b test="(x=Windows)">content</b>
>>
>> <b test="(z=Unix)">content</b>
>>
>> <b test="(y=Unix) and (y=Solaris)">content</b>
>>
>> <b test="(z=Unix) and (y=Windows7)">content</b>
>>
>> </a>
>>
>> Configuration/condition evaluation file (config.xml)
>>
>> <root>
>>
>> <condition name="x" value="Windows8"/>
>>
>> <condition name="z" value="Unix"/>
>>
>> <condition name="y" value="Solaris"/>
>>
>> <condition name="y" value="Windows7"/>
>>
>> </root>
>>
>> XSLT: test.xsl
>>
>> <xsl:variable name="conlist"><s><xsl:for-each
>> select="document('config.xml')// condition"><xsl:element
>> name="{@name}">test</xsl:element><xsl:element
>> name="{@value}">test</xsl:element></xsl:for-each></s></xsl:variable>
>>
>> <xsl:template match="*[@test]">
>>
>> <xsl:param name="t" select="concat('$', conlist,'//s','[',@test,']')"/>
>>
>>
>>
>> <xsl:if test='saxon:evaluate("$p1",$t)'>
>>
>> <xsl:copy-of select="."/>
>>
>> </xsl:if>
>>
>>
>>
>> </xsl:template>
>>
>>
>> Result:
>>
>> I'm getting true for all above <b> elements
>>
>> Expected result:
>>
>> 1st and 3rd <b> should not printed in the output (condition is failing)
>>
>>
>> Thanks in Advance,
>>
>> Balaji. M
>>
>>
>> On Mon, Oct 22, 2012 at 11:04 AM, M Balaji <msbalaji82@xxxxxxxxx> wrote:
>>>
>>> I need to construct the dynamic XPATH predicate from the input XML. I
>>> tried
>>> with evaluate function, but  its not converting the String to XPATH
>>> predicate. Can any one let me know how can I achieve this?
>>>
>>>   Input: test.xml
>>>
>>> <a>
>>>
>>> <b test=3D=94(x=3DWindows)=94>content</b>
>>>
>>> <b test=3D=94(z=3DUnix)=94>content</b>
>>>
>>> <b test=3D=94(y=3DUnix) and (y=3DSolaris)=94>content</b>
>>>
>>> <b test=3D=94(z=3DUnix) and (y=3DWindows7)=94>content</b>
>>>
>>> </a>
>>>
>>> Configuration/condition evaluation file (config.xml)
>>>
>>> <root>
>>>
>>> <condition name=3D=94x=94 value=3D=94Windows8=94/>
>>>
>>> <condition name=3D=94z=94 value=3D=94Unix=94/>
>>>
>>> <condition name=3D=94y=94 value=3D=94Solaris=94/>
>>>
>>> <condition name=3D=94y=94 value=3D=94Windows7=94/>
>>>
>>> </root>
>>>
>>> XSLT: test.xsl
>>>
>>> <xsl:variable name=3D"conlist"><s><xsl:for-each
>>> select=3D"document('config.xml')// condition"><xsl:element
>>> name=3D"{@name}">test</xsl:element><xsl:element
>>> name=3D"{@value}">test</xsl:element></xsl:for-each></s></xsl:variable>
>>>
>>> <xsl:template match=3D=94*[@test]=94>
>>>
>>> <xsl:param name=3D"t" select=3D"concat('$',
>>> conlist,'//s','[',@test,']')"/>
>>>
>>>
>>>
>>> <xsl:if test=3D'saxon:evaluate("$p1",$t)'>
>>>
>>> <xsl:copy-of select=3D"."/>
>>>
>>> </xsl:if>
>>>
>>>
>>>
>>> </xsl:template>
>>>
>>>
>>> Result:
>>>
>>> I'm getting true for all above <b> elements
>>>
>>> Expected result:
>>>
>>> 1st and 3rd <b> should not printed in the output (condition is failing)
>>>
>>>
>>> Thanks in Advance,
>>>
>>> Balaji. M

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.