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

  • Home
  • SEARCH
  • 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 7733059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:53:23+00:00 2026-06-01T06:53:23+00:00

I have a xsl:variable ($features-list) specified in my XSL which contains a tree fragment

  • 0

I have a xsl:variable ($features-list) specified in my XSL which contains a tree fragment from an external XML file.

<xsl:variable name="features-list" select="document('features-list.xml', /)" />

This file contains a list of “feature” elements where each element’s value specifies a feature name. In the XML which I’m trying to transform (it’s actually a RNG schema) certain elements have attributes conveniently named “if-feature” which specify that a copy of such an element (or rather an entire subtree) should only appear in the transformed document if such an attribute is not present OR if the attribute appears but has a same value as one of the feature elements in the external file. This may potentially mean that entire subtrees may be omitted in the result document since the attribute is “inherited” from ancestors.

I’ve successfuly used this variable to fire or omit certain templates using checks like

<xsl:when test="not(@if-feature) or @if-feature and $features-list//*[.=current()/@if-feature]">
</xsl:when>

in any template. But this will only work when comparing the entries in the features list with the element which is currently being processed by the template. What I’d need now is something like this:

<xsl:apply-templates select="descendant::foo[ancestor-or-self::*[not(@if-feature) or $features-list//*[.=current()/@if-feature]]]"/>

where current() refers to the one of the ancestor-or-self elements. I’m actually trying to fire a template based on a condition like this: only process foo descendants of the current node of which ancestors (and itself) – if they have an if-feature attribute – it’s value must match one of the feature element values in $feature-list.

Can I express such a condition using XPath only? How?

Would an XSLT solution be more appropriate here? This would identify offending elements but doesn’t help me much because of XSLT limitations.

<xsl:for-each select="descendant::foo">
    <xsl:for-each select="ancestor-or-self::*">
      <xsl:choose>
        <xsl:when test="@if-feature and not($features-list//*[.=current()/@if-feature])">
          <!-- we have a hit, break and do not proceed - but wait, this is XSLT, not Java -->
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
 </xsl:for-each>

Trying my best to learn XSLT 1.0 here, so please refrain from providing solutions for 2.0.

What I’m trying to accomplish is to extract a valid RNG schema from an existing one which specifies feature based subtrees. I’ve actually done that already but it doesn’t work for ONE tiny smallish rarely-occuring case which is now driving me nuts. Through walls of fire. And bricks.

Edit: the specification of my condition was unclear, so I corrected it.

  • 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-01T06:53:25+00:00Added an answer on June 1, 2026 at 6:53 am
    <xsl:apply-templates select="
      .//foo[not(
        ancestor-or-self::*[
          @if-feature and not( @if-feature = $features-list//text() )
        ]
      )]
    "/>
    

    The XPath = operator compares every node in a node set and yields true if one of the nodes fulfills the comparison. So, just compare @if-feature to a set of nodes.

    General notes.

    • XSLT is based around declaratively selecting the right nodes for processing and template matching. It is pretty good at that. It is not good with the imperative programming approach, so try to stop thinking Java.
    • Try to drop <xsl:for-each>. It does more harm than good, most of the time. Use <xsl:apply-templates> and <xsl:template> instead.
    • Prefer selecting the right nodes over selecting all nodes – unless you want to process all nodes.
    • Once nodes are selected, you cannot stop a loop. But you can decide whether its body is going to be executed or not.

    For example, the alphabetically first @if-feature:

    <xsl:for-each select="descendant::foo">
      <xsl:sort select="@if-feature" data-type="text" />
      <xsl:if test="position() = 1">
        <!-- ... -->
      </xsl:if>
    </xsl:for-each>
    

    This is not exactly the same as a breakpoint, but it has the same effect.

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

Sidebar

Related Questions

I have a xsl file where i need to use parameters from an external
I have an xsl page which uses <xsl:variable name=pos select=Position()/> in the onchange events
I have a xsl file that is grabbing variables from xml and they seem
I have something like the following code:: <xsl:variable name=sample> <xsl:copy-of select=//foo> <xsl:copy-of select=//bar> </xsl>
I have a variable $colors that is a string <xsl:variable name=colors select='red,green,blue,' /> I
I have this snippet of XSLT code: <xsl:variable name=key select=@*[1]/> But I need it
I have the following XSLT code that almost does what I want: <xsl:variable name=scoredItems
Hi I have one XSL variable <xsl:variable name=QTime select=response/lst/int[@name='QTime']/> Now I need to pass
I have the following scenario: <xsl:variable name=var1 select='SOME_DATA1' /> <xsl:if test='some_condition'> <xsl:variable name=var2 >
So, I have a variable containing a nodeset with several Size nodes <xsl:variable name=sizes

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.