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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:51:35+00:00 2026-06-01T03:51:35+00:00

I am transforming following XML to generate HTML. XML <clause code=section6> <variable col=1 name=R1C1

  • 0

I am transforming following XML to generate HTML.

XML

<clause code="section6">
      <variable col="1" name="R1C1" row="1">Water</variable>
      <variable col="2" name="R1C2" row="1">true</variable>
      <variable col="1" name="R2C1" row="2">Gas</variable>
      <variable col="2" name="R2C2" row="2"></variable>
      <variable col="1" name="R3C1" row="3">Petrol</variable>
      <variable col="2" name="R3C2" row="3">true</variable>
<clause>

XSLT

1: <xsl:for-each select="$clause/variable[@col='1']">
2:   <xsl:sort select="@row" data-type="number"/>
3:   <xsl:variable name="row-id" select="@row"/>
4:   <xsl:variable name="row" select="$clause/variable[@row=$row-id]"/>
5:   <xsl:if test="$clause/variable[@col='2' and @row=$row-id]='true'">
6:      <xsl:value-of name="row-no" select="concat(position(), ') ')"/>
7:      <xsl:value-of select="$clause/variable[@col='1' and @row=$row-id]"/>
8:   </xsl:if>
9: </xsl:for-each>


The transformation works fine and shows result 1) Water 3) Petrol

The issue is sequence number. You can see condition on Line 5 filters rows that only have ‘true’ value in col 2 and position() used for displaying sequence number. I cannot have running counter in XLST.

I was wondering if I can add condition of Line 5 with for-each at Line 1. The result with above example should be 1) Water 2) Patrol any advice?

  • 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-01T03:51:36+00:00Added an answer on June 1, 2026 at 3:51 am

    Does this do what you want?

    I drive the for-each selection on col 2 being true. That way position, which equals where we are in the selected set of nodes will equal 2 not 3

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    
        <xsl:template match="/">
            <xsl:for-each select="clause/variable[@col='2' and text()='true']">
                <xsl:sort select="@row" data-type="number"/>
                <xsl:variable name="row-id" select="@row"/>
                <xsl:value-of select="concat(position(), ') ')"/>
                <xsl:value-of select="/clause/variable[@col='1' and @row=$row-id]"/>
            </xsl:for-each>        
        </xsl:template>
    
    </xsl:stylesheet>
    

    Though I’d probably use templates in preference to the for-each and use current() so that we don’t need the row-id variable:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    
        <xsl:template match="/">
            <xsl:apply-templates select="clause/variable[@col='2' and text()='true']">
                <xsl:sort select="@row" data-type="number"/>            
            </xsl:apply-templates>        
        </xsl:template>
    
        <xsl:template match="clause/variable[@col='2' and text()='true']">
            <xsl:value-of select="concat(position(), ') ')"/>
            <xsl:value-of select="/clause/variable[@col='1' and @row=current()/@row]"/>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am transforming XML into HTML using XSLT. I have the following XML structure:
I'm transforming xml using the following code. It works fine for one xslt but
I have the following xml <AAA> <BBB>Total</BBB> </AAA> Transforming it with the following xslt
i want to transform some xml into HTML that has the following format: <TR><TD>
The following code works but is messy and slow. I am transforming an XDocument
I have trouble transforming the following code into the new django 1.3 class-based generic
I'm transforming XML to XML using the following XSLT. I need to validate the
XMLNotepad provides the following text (for example) when a transform fails: Error Transforming XML
I have the following sql query for transforming data but is it possible to
I have a html string held in memory after transforming to my desired template

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.