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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:27:33+00:00 2026-05-24T11:27:33+00:00

I’m looking for a workaround on passing parameters to a template-match. I’m aware this

  • 0

I’m looking for a workaround on passing parameters to a template-match. I’m aware this isn’t allowed within XPath, and therefore I’m looking for a ‘plan B’ solution.

This is what I wished would work :

Part 1 of xslt (2.0) :

<xsl:template match="/">
    <xsl:for-each select="//Main/PageList/Page">
    <xsl:result-document href="{@ID}.xml">
        <Page ID="{@ID}">
            <xsl:apply-templates select="node()">
                <xsl:with-param name="theID" select="@ID"/>
            </xsl:apply-templates>
        </Page>
    </xsl:result-document>
    </xsl:for-each> 
</xsl:template>

So fairly straightforward, don’t bother about the tags used, what it does in essence is go through a node, and for each node it creates a single XML file. Each node starts with an ID, and it’s this ID I’d like to make available for other templates. Unfortunately this works fine for named templates, but it doesn’t work for matched ones (if I understood the theory correctly at least)

So below is what I’d like to see working :

<!-- identity template -->
    <xsl:template match="node()|@*">
    <xsl:param name="theID"/>
    <xsl:copy>
        <xsl:apply-templates select="node()|@*">
            <xsl:with-param name="theID" select="$theID"/>
        </xsl:apply-templates>
    </xsl:copy>
</xsl:template>

<!-- lots of templates here doing what I want them to do -->

<!-- one template creating an issue -->

<xsl:template match="@src">
<!-- would be nice to know the current ID, but unfortunately this one stays empty... -->
<xsl:param name="theID"/>

<!-- clean current attribute a bit -->
<xsl:variable name="S1" select="replace(.,'\.\.\/','')"/>

<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="contains($S1,'common')">
<!-- just use current value, don't bother about current ID -->
    <xsl:value-of select="$S1"/>
</xsl:when>
<xsl:otherwise>
    <!-- use ID parameter -->
    <xsl:value-of select="concat($theID,'_',$S1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>

Don’t look at the code as such, it’s just a smaller part of the whole file, but the essence is that I want to use the ID parameter from my first part (match=”/”) inside the other template (match=”@src”), but this seems to be rather complex.

Am I missing something ? If I’m just having bad luck and it’s not possible indeed, would anyone have an advice how I could proceed ?

Thanks in advance !

  • 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-05-24T11:27:34+00:00Added an answer on May 24, 2026 at 11:27 am

    Your problem is here:

    <xsl:apply-templates select="node()">
      <xsl:with-param name="theID" select="@ID"/>
    </xsl:apply-templates>
    

    the select attribute specifies that the processing should continue on any children nodes of the current node.

    However node() only selects children nodes (elements, text nodes, processing instructions and comments) — not attributes.

    Solution:

    1. In order to directly cause processing of (all) attributes of the current node, use:

    —

    <xsl:apply-templates select="@*">
      <xsl:with-param name="theID" select="@ID"/>
    </xsl:apply-templates>
    

    .2. In order to cause the processing only of the src attribute of the current node use:

    —

    <xsl:apply-templates select="@src">
      <xsl:with-param name="theID" select="@ID"/>
    </xsl:apply-templates>
    

    .3. In order to process indirectly attributes tof the descendants of the current node, do:

    —

    <xsl:apply-templates select="node()|@*">
      <xsl:with-param name="theID" select="@ID"/>
    </xsl:apply-templates>
    

    You also must ensure that any template that processes node() must have an xsl:param named theID and that it must pass this param in any xsl:apply-templates instruction.

    In practice this means that you mus override all XSLT built-in templates, because they aren’t aware of your xsl:param.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for suggestions for debugging... If you view this site in Firefox or
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.