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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:14:46+00:00 2026-05-30T14:14:46+00:00

I have an XML like this: <?xml version=1.0 encoding=UTF-8?> <Section> <Chapter> <Cell colname=1> <Value>A</Value>

  • 0

I have an XML like this:

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

<Section>
    <Chapter>
        <Cell colname="1">
            <Value>A</Value>
        </Cell>
        <Cell colname="2">
            <MyValue>AAA</MyValue>
            <MyValue>BBB</MyValue>
        </Cell>
        <Cell colname="3">
            <MyCar>Honda</MyCar>
        </Cell>
    </Chapter>
    <Chapter>
        <Cell colname="1">
            <Value>C</Value>
        </Cell>
        <Cell colname="2">
            <MyValue>CCC</MyValue>
        </Cell>
        <Cell colname="3">
            <MyCar>Toyota</MyCar>
        </Cell>
    </Chapter>
</Section>

I like the have a message (later on convert them tags) output like this:

A
AAA
Honda
A
BBB
Honda
C
CCC
Toyota

This is my XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

    <xsl:output method="xml" version="1.0" encoding="iso-8859-1"   indent="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates select="Section//Chapter"/>
    </xsl:template>

    <xsl:template match="Chapter">
        <xsl:for-each select="Cell[@colname='2']//MyValue">
            <xsl:message>
                <xsl:value-of select="Cell[@colname='1']/Value"/>
                <xsl:value-of select="."/>
                <xsl:value-of select="Cell[@colname='3']/MyCar"/>
            </xsl:message>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="text()" />

</xsl:stylesheet>

Unfortunately it doesn’t output what I’d like it to do :(.

I realize that for-each will change the context so the remaining value-ofs won’t do anything.

What would be a solution for this ?.

TIA,

John

  • 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-30T14:14:47+00:00Added an answer on May 30, 2026 at 2:14 pm

    This XSLT 2.0 transformation (the equivalent XSLT 1.0 transformation can be mechanically written from this one).

    Do note: This is a generic solution that works with any number of children and doesn’t rely on hardcoded names.

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="Chapter">
      <xsl:apply-templates select="Cell[1]"/>
     </xsl:template>
    
     <xsl:template match="Cell">
      <xsl:param name="pText" as="xs:string*"/>
    
      <xsl:apply-templates select="*[1]">
       <xsl:with-param name="pText" select="$pText"/>
      </xsl:apply-templates>
     </xsl:template>
    
     <xsl:template match="Cell/*">
      <xsl:param name="pText" as="xs:string*"/>
    
      <xsl:variable name="vText" as="xs:string*"
       select="$pText, string(.)"/>
    
      <xsl:sequence select=
       "$vText
          [not(current()/../following-sibling::Cell)]"/>
      <xsl:apply-templates select="../following-sibling::Cell[1]">
        <xsl:with-param name="pText" select="$vText"/>
      </xsl:apply-templates>
      <xsl:apply-templates select="following-sibling::*">
        <xsl:with-param name="pText" select="$pText"/>
      </xsl:apply-templates>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <Section>
        <Chapter>
            <Cell colname="1">
                <Value>A</Value>
            </Cell>
            <Cell colname="2">
                <MyValue>AAA</MyValue>
                <MyValue>BBB</MyValue>
            </Cell>
            <Cell colname="3">
                <MyCar>Honda</MyCar>
            </Cell>
        </Chapter>
        <Chapter>
            <Cell colname="1">
                <Value>C</Value>
            </Cell>
            <Cell colname="2">
                <MyValue>CCC</MyValue>
            </Cell>
            <Cell colname="3">
                <MyCar>Toyota</MyCar>
            </Cell>
        </Chapter>
    </Section>
    

    produces exactly the wanted, correct result:

    A AAA Honda A BBB Honda C CCC Toyota
    

    Explanation:

    1. This is essentially a task for producing all combinations of values that belong to N groups (the children of a Cell make a group), taking one item from each group.

    2. At any item of group K, we add this item to the current combination of items of the groups 1, 2, …, K-1. Then we pass this newly formed combination to the group K+1. If we are an item in the last group (N), we print out (xsl:sequence) the whole accumulated combination.

    3. When the control returns, all combinations of elements of the remaining groups (K+1, K+2, …, N) have been appended to our current combination of the group items of groups 1, 2, …, K. All these combinations have already been printed.

    4. We pass the same group elements combination that was passed to us — now we pass it to the following item in the current group (the following-sibling).

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

Sidebar

Related Questions

I have an XML like this: <?xml version=1.0 encoding=UTF-8?> <Section> <Chapter> <Cell colname=1> <Value>A</Value>
I have a XML like this: <?xml version=1.0 encoding=UTF-8?> <Section> <Chapter> <nametable> <namerow> <namecell
I have XML-file with settings like this <?xml version=1.0 encoding=utf-8 ?> <configuration> <configSections> <sectionGroup
I have a xml like this: <?xml version=1.0 encoding=utf-8?> <assessment xmlns=http://xml.thinkcentral.com/pub/xml/hsp/assessment xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xhtml=http://www.w3.org/1999/xhtml xmlns:tia=http://xml.thinkcentral.com/pub/xml/hsp/tia
have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
I have an xml file which looks like this <?xml version=1.0 encoding=UTF-8 ?> <BulkDataExchangeRequests
I have a simple XML file like so: <?xml version=1.0 encoding=UTF-8?> <foo attr=blah &#176;
I would like to have an xml config file as follows: <?xml version=1.0 encoding=utf-8
I have the following sample nested XML <?xml version=1.0 encoding=UTF-8?> <text> <main> <div n=Section
hi i have an xml like this <?xml version=1.0?> <DataSetExchangeWMS xmlns=http://tempuri.org/DataSetExchangeWMS.xsd> <dtObjektInfo> <LanguageCode>1031</LanguageCode> <LiegenschaftID>7463</LiegenschaftID>

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.