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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:29:16+00:00 2026-05-28T03:29:16+00:00

In another thread another developer helped me by providing the awesome answer below. Basically

  • 0

In another thread another developer helped me by providing the awesome answer below.

Basically two templates are used to retrieve all of the data I need to present in my table.

My question now is how do I now apply a filter that will filter to both templates? I can successfully use xsl:value-of select="@Name[contains(.,NameIWant1)]" in the xsl:template match="SubGroup" but I cant figure out how to get it applied to xsl:template match="Data". I tried to use various name ways to no avail.

Thanks in advance you guys have been a huge help in me learnig XSLT!! kg

Sample XML

<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
<DataView Client="Client1" ID="1000" TimeStamp="12/7/2011 5:35:09 PM">
<Group ID="5000" Name="GroupName1">
<SubGroup ID="7000" Order="0" Name="NameIWant1">
<Data ID="1" Name="DataName1" Order="0">1</Data>
<Data ID="2" Name="DataName2" Order="0">2</Data>
<Data ID="3" Name="DataName3" Order="0">3</Data>
<Data ID="12" Name="DataName4" Order="0">4</Data>
</SubGroup>
<SubGroup ID="8000" Order="0" Name="NameIWant2">
<Data ID="1" Name="DataName1" Order="0">6</Data>
<Data ID="2" Name="DataName2" Order="0">7</Data>
<Data ID="3" Name="DataName3" Order="0">8</Data>
<Data ID="12" Name="DataName4" Order="0">9</Data>
</SubGroup>
</Group>
</DataView> 

Sample.xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>My Data</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Subgroup</th>
                        <th>DataName1</th>
                        <th>DataName2</th>
                        <th>DataName3</th>
                        <th>DataName4</th>
                    </tr>
                    <xsl:apply-templates/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="SubGroup">
        <tr>
            <td><xsl:value-of select="@Name"/></td>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>
    <xsl:template match="Data">
        <td><xsl:apply-templates/></td>
    </xsl:template>
</xsl:stylesheet>

I get this …

____________________________
NameIWant1 | 1 | 2 | 3 | 4 |
           | 6 | 7 | 8 | 9 |

I would like to get..

____________________________
NameIWant1 | 1 | 2 | 3 | 4 |
  • 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-28T03:29:17+00:00Added an answer on May 28, 2026 at 3:29 am

    The simplest way to filter SubGroup‘s by name is to move the expression into the match pattern, like this:

    <xsl:template match="SubGroup[contains(@Name, 'NameIWant1')]">
        <tr>
            <td><xsl:value-of select="@Name"/></td>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>
    

    And then ignore all other SubGroup elements with an empty template:

    <xsl:template match="SubGroup"/>
    

    Complete stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
        <xsl:strip-space elements="*"/>
        <xsl:template match="/">
            <html>
                <body>
                    <h2>My Data</h2>
                    <table border="1">
                        <tr bgcolor="#9acd32">
                            <th>Subgroup</th>
                            <th>DataName1</th>
                            <th>DataName2</th>
                            <th>DataName3</th>
                            <th>DataName4</th>
                        </tr>
                        <xsl:apply-templates/>
                    </table>
                </body>
            </html>
        </xsl:template>
        <xsl:template match="SubGroup[contains(@Name, 'NameIWant1')]">
            <tr>
                <td><xsl:value-of select="@Name"/></td>
                <xsl:apply-templates/>
            </tr>
        </xsl:template>
        <xsl:template match="SubGroup"/>
        <xsl:template match="Data">
            <td><xsl:apply-templates/></td>
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On another thread I saw a answer to a sql problem using Oracle's analytics.
[Note: There is another thread about this problem but it did not answer the
An answer and subsequent debate in the comments in another thread prompted me to
I'm trying to retrieve the SubItem in my ListView from another thread, but I
I have a thread push-backing to STL list and another thread pop-fronting from the
I originally started this question in another thread, but that thread was sorta, kinda
I want to access a scrollviewer from another thread. Please tell me how to
I have a windows form on the main thread and another thread that does
I have one thread that writes results into a Queue. In another thread (GUI),
Whenever I want to modify a winform from another thread, I need to use

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.