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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:35:27+00:00 2026-06-13T00:35:27+00:00

A transform (http://stackoverflow.com/questions/12862902/how-to-do-xslt-muenchian-grouping-with-some-null-attributes/12871809#12871809) groups based on an attribute (@group) and that attribute being null.

  • 0

A transform (http://stackoverflow.com/questions/12862902/how-to-do-xslt-muenchian-grouping-with-some-null-attributes/12871809#12871809) groups based on an attribute (@group) and that attribute being null. Initially this was for just concat-ing strings but I now need to extend it so it uses the string as a file location and concats the docs if they are grouped – if not grouped it should use the string as a file it gets but doesn’t need to join to anything else. The Transform:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="modules" match="module[@group]" use="concat(generate-id(..), '|', @group)"/>

<xsl:template match="root">
    <AllSections>
        <xsl:apply-templates />
    </AllSections>
</xsl:template>

<!-- NON GROUPED PART -->
<xsl:template match="module[not(@group)]">
    <page>
        <content>
            <xsl:value-of select="comp"/>
        </content>
    </page>
</xsl:template>

<!--GROUPED PART -->
<xsl:template match="module[@group][generate-id() = generate-id(key('modules', concat(generate-id(..), '|', @group))[1])]">
    <xsl:variable name="modules" select="key('modules', concat(generate-id(..), '|', @group))"/>
    <page>
        <content>
            <xsl:apply-templates select="$modules/comp/text()"/>
        </content>
        <count>
            <xsl:value-of select="count($modules)" />
        </count>
    </page>
</xsl:template>

<xsl:template match="module"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

And Sample Input:

<root>
<section>
<subsection>
    <module>
        <comp>111</comp>
    </module>
    <module group='group01'>
        <comp>222</comp>
    </module>
    <module group='group01'>
        <comp>333</comp>
    </module>
    <module>
        <comp>444</comp>
    </module>
    <module>
        <comp>555</comp>
    </module>
</subsection>
</section>
<section>
<subsection>
    <module group ="group02">
        <comp>666</comp>
    </module>
    <module group ="group02">
        <comp>777</comp>
    </module>
    <module>
        <comp>888</comp>
    </module>
    <module group ="group03">
        <comp>999</comp>
    </module>
    <module group ="group03">
        <comp>101010</comp>
    </module>
</subsection>
<subsection>
    <module group ="group04">
        <comp>11111</comp>
    </module>
    <module group ="group04">
        <comp>121212</comp>
    </module>
    <module group ="group05">
        <comp>131313</comp>
    </module>
    <module group ="group05">
        <comp>141414</comp>
    </module>
    <module group ="group06">
        <comp>151515</comp>
    </module>
    <module group ="group06">
        <comp>161616</comp>
    </module>
    <module>
        <comp>171717</comp>
    </module>
</subsection>

The transform at the moment concats the comp strings if they are of the same group… doing this for the non-grouped parts so the string is used as a file location:

    <!-- NON GROUPED PART -->
<xsl:template match="module[not(@group)]">
    <page>
        <content>
            <xsl:variable name="var">
               <xsl:value-of select="comp"/>
            </xsl:variable>
            <xsl:copy-of select="document(concat('../myfile/', string($var)))"/>
        </content>
    </page>
</xsl:template>

At the moment the GROUPED PART will output:

…

<page>
        <content>strgin1string2</content>
        <count>2</count>
</page>

…

I need:

…

<page>
        <content>
         TEXT FROM FILE CALLED string1
         TEXT FROM FILE CALLED string2
        </content>
        <count>2</count>
</page>

…

Thanks!

  • 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-13T00:35:29+00:00Added an answer on June 13, 2026 at 12:35 am

    Assuming you simply want to pull in complete XML documents you can change your code to

    <xsl:template match="module[@group][generate-id() = generate-id(key('modules', concat(generate-id(..), '|', @group))[1])]">
        <xsl:variable name="modules" select="key('modules', concat(generate-id(..), '|', @group))"/>
        <page>
            <content>
                <xsl:copy-of select="document($modules/comp)"/>
            </content>
            <count>
                <xsl:value-of select="count($modules)" />
            </count>
        </page>
    </xsl:template>
    

    [edit] I think my suggestion above works if the comp elements contain the complete URL. Your comment however suggests you want to concatenate a constant with each comp, in that case with XSLT 1.0 you need

    <xsl:template match="module[@group][generate-id() = generate-id(key('modules', concat(generate-id(..), '|', @group))[1])]">
        <xsl:variable name="modules" select="key('modules', concat(generate-id(..), '|', @group))"/>
        <page>
            <content>
                <xsl:for-each select="$modules/comp">
                  <xsl:copy-of select="document(concat('../myfile/', .))"/>
                </xsl:for-each>
            </content>
            <count>
                <xsl:value-of select="count($modules)" />
            </count>
        </page>
    </xsl:template>
    

    With XSLT 2.0 you could write a compact line like <xsl:copy-of select="document($modules/comp/(concat('../line/', .))"/> but with XSLT 1.0 the for-each should do.

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

Sidebar

Related Questions

We use Microsoft Ajax (ajaxmin.tasks) approach which described in this one (http://stackoverflow.com/questions/5043504/using-microsoft-ajax-minifier-with-visual-studio-2010-1-click-publish) to minify
I'm working with PostgreSQL. I need to transform http://www.xyz.com/some_uri/index1.html in something like scdfdsffd(some unique
I found and followed an example from Stackoverflow (http://stackoverflow.com/questions/2310139/how-to-read-xml-response-from-a-url-in-java) of how to read an
Attempting to import a TextProperty, similar to another Stack Overflow question (http://stackoverflow.com/questions/3434090/app-engine-badvalueerror-on-bulk-data-upload-textproperty-being-construed-as-s) After adding
After going through so many documents and online content like: http://stackoverflow.com/questions/4066167/sencha-touch-or-jquery-mobile http://stackoverflow.com/questions/5093691/sencha-touch-vs-jqtouch-vs-gwt-mobile-vs-xui-vs-jquery-mobile-vs http://www.quora.com/Were-deciding-between-jQuery-Mobile-currently-in-alpha-and-Sencha-Touch-What-are-the-pros-and-cons-for-each http://interfacethis.com/2011/adventures-in-html5-part-one/
I'd like to transform an URL like this http://www.mydomain.com/it/archive.php=321123 in one like the following
How can I transform: http://example.com/about.php http://example.com/hello/deep.php http://example.com/hello/world/deeper.php Dynamically, into URLs like: http://example.com/about/ http://example.com/hello/deep/ http://example.com/hello/world/deeper/
I want to make a rule that transform this URL: http://www.example.com/product.php?category=1&product=5 Into http://www.example.com/brother-2035 (The
I have the following in 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/02/xpath-functions
As far as I understand, Response.Redirect(http://stackoverflow.com); tells the browser to initiate a request to

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.