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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:03:27+00:00 2026-05-31T19:03:27+00:00

I have the following problem: Within a stylesheet document I want to create an

  • 0

I have the following problem:

Within a stylesheet document I want to create an output from a relativly simple xml file.
While most of the common XPath and XSLT stuff is not that difficult, comparing two elements and deciding, how to go on is quite a problem right now.

example xml:

<root>
    <foo>
        <value>1</value>
        <name>foo1</name>
    </foo>
    <foo>
        <value>2</value>
        <name></name>
    </foo>
    <foo>
        <value>3</value>
        <name>foo3</name>
    </foo>

    <bar>
        <value>1</value>
    </bar>
    <bar>
        <value>2</value>
    </bar>
</root>

within the stylesheet is a xsl:for loop, that tries to decide, whether or not the current node shall be displayed:

[...]
<xsl:for-each select="bar">
    <xsl:if test="//foo[value=./value]/name">
        <!-- go on, if the content of the 'name' element is not empty -->
    </xsl:if>
</xsl:for-each>
[...]

The intention was only to go on with the stuff, if the content of the ‘name’ element from ‘foo’ is not empty, using the euqality of the ‘value’ element.
The result is, that every line from ‘bar’ creates an output, event if I intended not to have one for the second entry, since ‘//foo[2]/name’ is empty.

I’m not sure, how to proceed at the moment… Maybe a generated key would be sufficent!? I don’t know…

Thanks for every comment!

  • 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-31T19:03:28+00:00Added an answer on May 31, 2026 at 7:03 pm

    You probably want to use something like the following:

    <xsl:template match="/">
        <root>
            <xsl:for-each select="//bar">
                <xsl:for-each select="//foo[value=current()/value]">
                    <xsl:if test="name != ''">
                        <xsl:copy-of select="."/>
                    </xsl:if>
                </xsl:for-each>
            </xsl:for-each>
        </root>
    </xsl:template>
    

    Most striking is of course that you should use current()/value instead of ./value, because current() refers to the bar element, and . refers to the foo element looped over.

    When applied to the input supplied, this gives

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
        <foo>
            <value>1</value>
            <name>foo1</name>
        </foo>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following problem. I am executing an OS command line from within
I've got a following problem: I have configured a ant plugin within my pom.xml
I have the following problem with XSLT. In an XML document I have several
I have the following problem. I have some text within a javascript. I want
I have the following data that I parsed from an xml file and now
I have the following problem using template instantiation [*]. file foo.h class Foo {
I am new in xslt. I have the following problem. I need within an
I have the following problem - from the server side I get a string
I have an interesting problem with XSL. We have an XML Input file that
I have the following problem with QT model/view framework. I want to render 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.