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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:05:28+00:00 2026-05-27T12:05:28+00:00

This is what I am trying to achieve: I have a CSV file which

  • 0

This is what I am trying to achieve:
I have a CSV file which has data like 1,4,5..and so on(not a fixed series) and I have an XML which is having certain node repeating. Now from that XML I need to remove all those nodes whose position is present in the the CSV file.

This is how I am trying to do it:
I am passing the CSV file as parameter to XSLT and calling a recursive template to print the XML. (Thanks to a post I had seen long time back..don’t remember the address)

Problem: “This is not working” 🙂

Below is my sample XML and XSLT. Any help would be appreciated.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Items>
    <Item IItemID="">
    </Item>
    <Item ItemID="100-8754">
    </Item>
    <Item ItemID="206-4141">
    </Item>
    <Item ItemID="">
    </Item>
</Items>

Here is the XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
    <xsl:param name="ErrorPos" as="xs:string" select="'1,4'"/>
    <xsl:template match="*|/">
                <xsl:call-template name="commaSplit">
            <xsl:with-param name="dataString" select="$ErrorPos"/>
            <xsl:with-param name="position" select="1"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="commaSplit">
        <xsl:param name="dataString"/>
        <xsl:param name="position"/>
            Vivek
        <xsl:choose>
            <xsl:when test="contains($dataString,',')">
                <!-- Select the first value to process -->
                <xsl:call-template name="getItems">
                    <xsl:with-param name="errorPosition" select="substring-before($dataString,',')"/>
                    <xsl:with-param name="position" select="$position"/>
                </xsl:call-template>
                <!-- Recurse with remainder of string -->
                <xsl:call-template name="commaSplit">
                    <xsl:with-param name="dataString" select="substring-after($dataString,',')"/>
                    <xsl:with-param name="position" select="$position + 1"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <!-- This is the last value no need to  recurse -->
                <xsl:call-template name="getItems">
                    <xsl:with-param name="errorPosition" select="$dataString"/>
                    <xsl:with-param name="position" select="$position"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!-- Process of individual value here -->
    <xsl:template name="getItems" match="/">
        <xsl:param name="errorPosition"/>
        <xsl:param name="position"/>
        <Items>
            <xsl:value-of select="$errorPosition"/>
            <xsl:value-of select="concat(',',$position)"/><!--Just for testing...will be replaced by copy statement-->
        </Items>
    </xsl:template>

</xsl:stylesheet>
  • 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-27T12:05:29+00:00Added an answer on May 27, 2026 at 12:05 pm

    your problem is because you have 2 templates which both match “/” the root of the xml document, in order to funnel the data correctly you must ensure a priority is set on the template you wish to execute first! since you are using named templates you can simply remove the match attribute off the getItems template!

    with this minor change it works, unless you have a different output desired?

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
        <xsl:param name="ErrorPos" as="xs:string" select="'1,4'"/>
        <xsl:template match="*|/" priority="999">
                    <xsl:call-template name="commaSplit">
                <xsl:with-param name="dataString" select="$ErrorPos"/>
                <xsl:with-param name="position" select="1"/>
            </xsl:call-template>
        </xsl:template>
        <xsl:template name="commaSplit">
            <xsl:param name="dataString"/>
            <xsl:param name="position"/>
                Vivek
            <xsl:choose>
                <xsl:when test="contains($dataString,',')">
                    <!-- Select the first value to process -->
                    <xsl:call-template name="getItems">
                        <xsl:with-param name="errorPosition" select="substring-before($dataString,',')"/>
                        <xsl:with-param name="position" select="$position"/>
                    </xsl:call-template>
                    <!-- Recurse with remainder of string -->
                    <xsl:call-template name="commaSplit">
                        <xsl:with-param name="dataString" select="substring-after($dataString,',')"/>
                        <xsl:with-param name="position" select="$position + 1"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <!-- This is the last value no need to  recurse -->
                    <xsl:call-template name="getItems">
                        <xsl:with-param name="errorPosition" select="$dataString"/>
                        <xsl:with-param name="position" select="$position"/>
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <!-- Process of individual value here -->
        <xsl:template name="getItems" match="/">
            <xsl:param name="errorPosition"/>
            <xsl:param name="position"/>
            <Items>
                <xsl:value-of select="$errorPosition"/>
                <xsl:value-of select="concat(',',$position)"/><!--Just for testing...will be replaced by copy statement-->
            </Items>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Regards,
    Sam

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

Sidebar

Related Questions

im trying to achieve the following, in php i have a form like this:
I've trying to achieve something like this: class Base { public: Base(string S) {
I'm trying to achieve URLs like this in Rails: http://localhost/posts/1234/post-slug-name with both ID and
What I am trying to achieve is something like this: class object: def __init__(self):
What I'm trying to achieve: 1) http://localhost/en/script.php?param1=random is mapped to http://localhost/script.php?param1=random&language=English This has to
I'm not sure if this is possible what I'm trying to achieve. I want
Im trying to achieve an output like this {status:ok,0:{id:11,title:digg,url:http://www.digg.com}} but instead i am getting
This is what I am trying to achieve: DataTable populated using data from non
I'm trying to achieve something like you have in the back end of Wordpress
I have simplified what I am trying to achieve from my previous question. This

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.