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 8117763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:16:43+00:00 2026-06-06T04:16:43+00:00

I have to make xPath dynamical, based on my request attributes in XSL file

  • 0

I have to make xPath dynamical, based on my request attributes in XSL file making JSP using expression language. So now I have this thing:

<xsl:variable name="xPath">@name='${categoryName}'</xsl:variable>
<xsl:for-each select="tar:products/category[$xPath]/subcategory">

But this doesn’t work. So the question is how to get round this problem and make xPath work?


Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tar:products SYSTEM "products.dtd" >
<?xml-stylesheet type='text/xsl' href='products2HTML.xsl'?>
<tar:products xmlns:tar="http://www.epam.com/products"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.epam.com/products products.xsd ">
<category name="Electronics">
    <subcategory name="mp3">
        <product name="iPod 4g">
            <provider>Apple</provider>
            <model>Qd246</model>
            <dateOfIssue>11-11-2012</dateOfIssue>
            <color>white</color>
            <notInStock/>
        </product>
        <product name="Cowon">
            <provider>Cowon</provider>
            <model>sF223</model>
            <dateOfIssue>13-12-2012</dateOfIssue>
            <color>black</color>
            <price>13456</price>
        </product>
        <product name="IRiver">
            <provider>IRiver e30</provider>
            <model>Ir234</model>
            <dateOfIssue>13-12-2012</dateOfIssue>
            <color>black</color>
            <price>13456</price>
        </product>
    </subcategory>
    <subcategory name="Computers">
        <product name="iMac">
            <provider>Apple</provider>
            <model>Mm232</model>
            <dateOfIssue>20-02-2012</dateOfIssue>
            <color>silver</color>
            <notInStock/>
        </product>
        <product name="PC">
            <provider>Acer</provider>
            <model>Ae135</model>
            <dateOfIssue>22-11-2012</dateOfIssue>
            <color>black</color>
            <price>13456</price>
        </product>
    </subcategory>
</category>
<category name="Toys">
    <subcategory name="Electronical toys">
        <product name="Cat">
            <provider>UrkToy</provider>
            <model>cC246</model>
            <dateOfIssue>11-11-2012</dateOfIssue>
            <color>grey</color>
            <price>1100</price>
        </product>
        <product name="Dog">
            <provider>LatToy</provider>
            <model>Ld223</model>
            <dateOfIssue>03-12-2012</dateOfIssue>
            <color>white</color>
            <price>13456</price>
        </product>
    </subcategory>
    <subcategory name="Fabric toys">
        <product name="Bear">
            <provider>RusToy</provider>
            <model>BB122</model>
            <dateOfIssue>20-02-2012</dateOfIssue>
            <color>brown</color>
            <notInStock/>
        </product>
        <product name="Bird">
            <provider>BelToy</provider>
            <model>Bb110</model>
            <dateOfIssue>05-11-2012</dateOfIssue>
            <color>red</color>
            <price>500</price>
        </product>
    </subcategory>
</category>
</tar:products>

I put parameter categoryName in request from my previous page and it’s successfully shown on my page, so problem is not in it.
Here is more info about xsl file:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:tar="http://www.epam.com/products"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.epam.com/products products.xsd ">
<xsl:output method="html" />
<xsl:param name="categoryName" select="'${categoryName}'"></xsl:param>
<xsl:template match="/">
    <table border="1">
        <tr bgcolor="#CCCCCC">
            <td align="center">
                <strong>
                    Subcategories
                            </strong>
            </td>
        </tr>
        <xsl:value-of select="$categoryName"/><!-- this string works -->
        <xsl:for-each select="tar:products/category[@name=$categoryName]/subcategory">
            <xsl:sort order="descending" select="count(product)"
                data-type="number" />
            <a href="controller?command=products&amp;name={@name}">
            <tr bgcolor="#F5F5F5">
                <td>
                    <xsl:value-of select="@name" />
                    (
                    <xsl:value-of select="count(product)" />
                    )
                </td>

            </tr>
            </a>
        </xsl:for-each>
    </table>
    <form method="post" action="/controller?command=back">
        <input type="submit" value="Back"/>
    </form>
</xsl:template>
 </xsl:stylesheet>

Expected output,when request parameter categoryName equals 'Toys':

enter image description here


Actual output:

enter image description here


RESOVLED

In my java class I’ve put parameter in request before transformation, but needed simply to put it in transformator parameters:

transformer.setParameter("categoryName", name);
  • 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-06T04:16:45+00:00Added an answer on June 6, 2026 at 4:16 am

    If you really need to have dynamically built XPath, you will need to make use of an extension function. For example, you may be able to use the EXSTL Dynamic Extension Function.

    However, looking at your rather terse code sample, I am not sure you need the extra complexity in this case. Could you two lines be simplified to the following:

    <xsl:for-each select="tar:products/category[@name=$categoryName]/subcategory">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XPath expression: //*[@name='outputFormat']/ows:Value I would like to make it case
Using this sample : I have make my own Fragment that holds tabhost and
I have to make a graph based on a list of items. For this
I have a large xml file (1Gb). I need to make many queries on
Using xslt/xpath, I need to be able to select the two elements which have
I have been using com.sun.org.apache.xpath.internal.XPathAPI for some time and it seems to work ok.
I have a json file/stream, i like to be able to make select SQL
I have make this script: $(#comments .comment .links).hide(); $(#comments .comment).hover( function() { $(.links, this).stop(true).slideDown(300);
I have make a new dropdown navi in css . Chrome, firefox, safari is
I have make a messaging system in which user can send messages to each

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.