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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:23:43+00:00 2026-05-11T21:23:43+00:00

I have an xml output like this: <data> <item-types> <entry id=1 items=5> <category>Frozen</category> </entry>

  • 0

I have an xml output like this:

<data>
    <item-types>
        <entry id="1" items="5">
            <category>Frozen</category>
        </entry>
        <entry id="2" items="4">
            <category>Breakfast</category>
        </entry>
    </item-types>

    <items>
        <entry id="28">
            <item-number>1115</item-number>
            <name>Marion Berries, IQF</name>
            <area>
                <item id="1">Groceries - Frozen</item>
            </area>
        </entry>
        <entry id="29">
            <item-number>1117</item-number>
            <name>Peach Cups</name>
            <area>
                <item id="1">Groceries - Frozen</item>
            </area>
        </entry>
        <entry id="35">
            <item-number>1570</item-number>
            <name>Sausage Patty</name>
            <area>
                <item id="2">Groceries - Breakfast</item>
            </area>
        </entry>
        <entry id="32">
            <item-number>1575</item-number>
            <name>French Toast Stix, WG</name>
            <area>
                <item id="2">Groceries - Breakfast</item>
            </area>
        </entry>
    </items>
</data>

The items-types are the categories of the items below. item-types/entry/@id relates directly to items/entry/area/item/@id and I’m trying to organize the items in to the categories for my output.

So far I am using the following XSL transformation.

<xsl:template match="item-types/entry">
    <h3><xsl:value-of select="concat(@id,'. ',category)" /></h3>
    <ul>
        <xsl:apply-templates select="/data/items/entry[area/item/@id = @id]" />
    </ul>
</xsl:template>
<xsl:template match="items/entry">
    <li>
        <xsl:value-of select="concat(item-number,'. ',name,' (',area/item/@id,')')" />
    </li>
</xsl:template>

The problem is it’s not working. I believe the problem is the predicate on line 4 of the transformation: [area/item/@id = @id] When I remove this, it shows all the items in every category.

Is there a way to show the “Frozen” items in the “Frozen” category and the “Breakfast” items in the “Breakfast” category?

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-05-11T21:23:44+00:00Added an answer on May 11, 2026 at 9:23 pm

    Easily done with an XSL key.

    <xsl:key name="kEntryByAreaId" match="items/entry" use="area/item/@id" />
    
    <!-- this is just for the sake of the test -->
    <xsl:template match="/data">
      <xsl:apply-templates select="item-types/entry" />
    </xsl:template>
    
    <xsl:template match="item-types/entry">
      <h3>
        <xsl:value-of select="concat(@id,'. ',category)" />
      </h3>
      <ul>
        <xsl:apply-templates select="key('kEntryByAreaId', @id)" />
      </ul>
    </xsl:template>
    
    <xsl:template match="items/entry">
      <li>
        <xsl:value-of select="
          concat(
            item-number, 
            '. ', name,
            ' (', area/item/@id, ')'
          )
        " />
      </li>
    </xsl:template>
    

    Now to answer the question why your try did not work.

    This expression:

    /data/items/entry[area/item/@id = @id]
    

    says: “all the /data/items/entry elements with their area/item/@id value equal to their @id value”. Trouble is – they have no @id value.

    What you mean is this:

    /data/items/entry[area/item/@id = current()/@id]
    

    This would work, but the key will be faster.

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

Sidebar

Related Questions

I have XML file (output of some application) like this: <data> <call function=get_user_data> <output>
I have some data in an XML element that looks like this: <item value=category1,category2>Item
I have XML like, <items> <item> <products> <product>laptop</product> <product>charger</product> <product>Cam</product> </products> </item> <item> <products>
I have XML like this: <exam> <section name=SampleSection1> <attributes> <variable_name data_type=String value=SCORE/> </attributes> <item
Essentially, I have XML structured like this: <A> <B> <1>data</1> <2>data</2> <C> <1>data</1> <2>data</2>
I have an XML structure that looks like this: <root> <index> <item>item 1</item> <item>item
I have XML data like this: <data ItemCount=5> <zrow GroupName=ManagerUser=User1 /> <zrow GroupName=DeveloperUser=User2 />
I have an XML string like this: <DATA> <CHILD_DATA ATVAL=value1/> <CHILD_DATA /> </DATA> The
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>

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.