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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:53:42+00:00 2026-05-13T09:53:42+00:00

I guess my problem is quite common, so there must be an easy solution.

  • 0

I guess my problem is quite common, so there must be an easy solution. Consider the following xml snippet:

  <categories>
    <category name="cat1" />
    <category name="cat2" />
    <category name="cat3" />
    <category name="cat4" />
  </categories>
  <data>
    <catval name="cat2">foo</catval>
    <catval name="cat4">bar</catval>
    <catval name="cat3">boo</catval>
  </data>

I need to output the catval values in the order defined in the categories element (including categories that have no data). Please note that in the real input xml, there are multiple data elements all over the place and the output is way more complex, so creating a template for categories is not feasible. I am using a construct like the following:

<xsl:template match="data">
    <xsl:variable name="currentdata" select="." />
    <xsl:for-each select="../categories/category">
      <xsl:value-of select="@name" />: 
      <xsl:value-of 
        select="$currentdata/catval[@name=@name]" /> <!-- ??? -->
    </xsl:for-each>
</xsl:template>

I don’t know if this is the best approach to solve my problem, but even if it isn’t: How can I match the name attribute of $currentdata/catval to the name attribute of the category element in the context of the for-each loop?

  • 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-13T09:53:42+00:00Added an answer on May 13, 2026 at 9:53 am

    Use a variable to save the attribute value from the <xsl:for-each> scope:

    <xsl:template match="data">
      <xsl:variable name="currentdata" select="." />
      <xsl:for-each select="../categories/category">
        <xsl:variable name="name" select="@name"/>
        <xsl:value-of select="$name" />: 
        <xsl:value-of 
          select="$currentdata/catval[@name=$name]" /> <!-- ??? -->
      </xsl:for-each>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess it's quite a common problem in databinding scenarios. What do you usually
I am sure that this must be quite a common problem so I would
I know this looks embarrassingly easy, and I guess the problem is that I
My Problem is the following. I got this code and i guess a corrupt
This is probably an easy one, but I'm missing something I guess. The problem
Im pretty sure the answer must be quite easy, but for some reason I
The description of the problem is quite easy... I have an enum placed inside
I guess the problem is that I do not know how to use factory
i am getting a problem while populating data inside the dropdown... I guess since
I guess my general question which I googled to no luck: Is there a

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.