Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:38:36+00:00 2026-06-17T16:38:36+00:00

I am trying to evaluate a dynamic xpath using ixsl:eval() in Saxon-ce with xslt

  • 0

I am trying to evaluate a dynamic xpath using ixsl:eval() in Saxon-ce with xslt 2.0 but does not seem to be working. Here is the illustrative XML

<things>
  <thing>
    <name>widget one</name>
    <number>10</number>
    <type>metal</type>
    <subtypes>
      <subtype>red<subtype>
    </subtypes>
  </thing>
  <thing>
    <name>widget two</name>
    <number>11</number>
    <type>wood</type>
    <subtypes>
      <subtype>red</subtype>
      <subtype>blue</subtype>
    </subtypes>
  </thing>
</things>

and a piece of the xsl 2.0 style sheet I am trying to eval (the various parameters are passed by another part of the larger xsl stylesheet)

<template name="display" match="things">
  <xsl:param name="num"/>
  <xsl:param name="type" as="xs:string"/>
  <xsl:param name="subtype" as="xs:string"/>

  <xsl:variable name="xpathExp" as="xs:string">
     <xsl:text>things/thing</xsl:text>
     <xsl:if test="not($num = 'all')>
       <xsl:copy-of select="concat('[number=',$num,']')"/>
     </xsl:if>
     <xsl:if test="not($type = 'all')>
        <xsl:copy-of select="concat('[type=''',$type,''']')"/>
     </xsl:if>
     <xsl:if test="note($subtype = 'all')>
         <xsl:copy-of select="concat('[subtype/subtypes=''',$subtype,''']')/>
     </xsl:if>
   </xsl:variable>

   <xsl:result-document href="#display" method="ixsl:replace-content">

   <xsl:for-each select="ixsl:eval($xpathExp)">
      <xsl:sort select="name"/>
   </xsl:for-each>

</template>

When I replace the eval statement with a explicit xpath statement the code works, so for some reason the eval on $xpathExp is not working. Ideas?

* Edit *
Here is a better XML example:

<things>
  <thing>
    <name>widget one</name>
    <number>10</number>
    <type>metal</type>
    <subtypes>
      <subtype>red<subtype>
    </subtypes>
  </thing>
  <thing>
    <name>widget two</name>
    <number>11</number>
    <type>wood</type>
    <subtypes>
      <subtype>red</subtype>
      <subtype>blue</subtype>
    </subtypes>
  </thing>
  <thing>
    <name>widget three</name>
    <number>11</number>
    <type>metal</type>
    <subtypes>
      <subtype>blue</subtype>
    </subtypes>
  </thing>
</things>

The user can select values via dropboxes for number, type and subtype. Depending on the user’s selection, a list of thing names is displayed. So for example, if the user selects a number of 11 and the subtype of red it would just display widget two. If they select instead a subtype of blue it would display the name of widgets two and three.

So the base xpath filter is things/thing. If the user selects a number value I want to append [number=$num] to the xpath expression so ti would be things/thing[number=$num]. If they select more than one item, lets say number and type, [number=$num][type=$type] would be appended to the base xpath and I would have things/thing[number=$num][type=$type].

Basically what I trying to avoid is having to individually code all possible permutations and combinations of possible user selections.

Does that help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:38:37+00:00Added an answer on June 17, 2026 at 4:38 pm

    The ixsl:eval function is for dynamic evaluation of JavaScript, not XPath. From the Saxon-CE documentation:

    …Executes Javascript code, supplied as a string. The supplied script is
    injected into the DOM as a function which is evaluated immediately to
    return a result.

    For the code sample you provide, dynamic evaluation is not required. Only certain classes of XSLT application actually require dynamic XPath evaluation.

    In the few cases where dynamic XPath evaluation is required, Saxon-CE has no built-in capability, so instead of just building an XPath dynamically, you would need to generate a simple ‘wrapper’ XSLT and execute this using the Saxon-CE JavaSCript API. This technique is used in the PathEnq online XPath 2.0 evaluator.

    The following code achieves something similar to your code using a single ‘static’ XPath expression – in this example, a further template is applied to the required ‘thing’ element to create usable HTML:

    rendered code (syntax-highlighted and formatted)

    enter image description here

    source code:

    <xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
    xmlns:js="http://saxonica.com/ns/globalJS"
    xmlns:prop="http://saxonica.com/ns/html-property"
    xmlns:style="http://saxonica.com/ns/html-style-property"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs prop"
    extension-element-prefixes="ixsl"
    version="2.0"
    >
    <xsl:template name="main" match="/">
    <xsl:call-template name="display"/>
    </xsl:template>
    
    <xsl:template name="display">
    <xsl:param name="num" as="xs:string" select="'none'"/>
    <xsl:param name="type" as="xs:string" select="'all'"/>
    <xsl:param name="subtype" as="xs:string" select="'red'"/>
    
    <xsl:variable name="thingsEl" select="things" as="element(things)"/>
    
    <xsl:variable name="widget" as="element()+"
    select="if ($num eq 'all')
    then $thingsEl/thing[number = $num]
    else if ($type ne 'all')
        then $thingsEl/thing[type = $type]
    else $thingsEl/thing[subtypes/subtype = $subtype]"/>
    
    <xsl:result-document href="#display" method="append-content">
    <xsl:apply-templates select="$widget">
    <xsl:sort select="name"/>
    </xsl:apply-templates>
    </xsl:result-document>
    
    </xsl:template>
    
    <xsl:template match="thing">
    <ol>
    <li>name: <xsl:value-of select="name"/></li>
    <li>number: <xsl:value-of select="number"/></li>
    <li>type: <xsl:value-of select="type"/></li>
    <li>subtypes: 
    <ol>
    <xsl:apply-templates select="subtypes/subtype"/>
    </ol>
    </li>
    </ol>
    </xsl:template>
    
    <xsl:template match="subtype">
    <li><xsl:value-of select="."/></li>
    </xsl:template>
    
    </xsl:transform>
    

    The HTML output (outerHTML view of the ‘display’ div element)

    <div id="display">
        <ol>
            <li>name: widget one</li>
            <li>number: 10</li>
            <li>type: metal</li>
            <li>subtypes: 
                <ol>
                    <li>red</li>
                </ol></li>
        </ol>
        <ol>
            <li>name: widget two</li>
            <li>number: 11</li>
            <li>type: wood</li>
            <li>subtypes: 
                <ol>
                    <li>red</li>
                    <li>blue</li>
                </ol></li>
        </ol>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to evaluate an xml node using xpath and i'm not sure why
I'm trying to evaluate Ruport for use in my Rails app, but am not
I've been trying to evaluate if this array list is empty or not but
I'm trying to evaluate an XPath varable I'm building dynamically based on the position
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Simple problem, actually. I am trying to evaluate the possibilities of Google Apps, using
I'm trying to evaluate something like this but more complex, but I get a
I'm trying to evaluate the weborb integration product, but I'm having troubles getting it
I'm trying to evaluate the contents of a call stack in WindDbg using the
I'm trying to evaluate content repositories ( JSR283 ) like Jackrabbit and ModeShape but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.