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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:47:47+00:00 2026-05-26T10:47:47+00:00

I try to get duplicate address for a object but i don’t understand why

  • 0

I try to get duplicate address for a object but i don’t understand why my foreach doesn’t work. I think it’s because of the function generate-id().

I expect the following result :

<ul>
<li>1.1.1.1</li>
<li>host1</li>
<li>host2</li>
<li>host5</li>
<li>host7</li>
</ul>

<ul>
<li>2.2.2.2</li>
<li>host8</li>
<li>host9</li>
</ul>

Your help would be appreciated

This is my xls :

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <HTML>
      <HEAD>
        <TITLE>Template</TITLE>
      </HEAD>
      <BODY BGCOLOR="#FFFFFF">
        <xsl:apply-templates />
      </BODY>
    </HTML>
  </xsl:template>
  <xsl:key name="same-ip" match="db/OBJECT/PROPERTY[@NAME='address']" use="@VALUE" />
  <xsl:template match="db/OBJECT">

    <xsl:for-each select="//db/OBJECT/PROPERTY[@NAME='address']/@VALUE[generate-id(.)=generate-id(key('same-ip',@VALUE)[1])]"> 
      <ul>
      <li><xsl:value-of select='//db/OBJECT/PROPERTY[@NAME="address"]/@VALUE'/> </li>
      <li><xsl:value-of select='//db/OBJECT/PROPERTY[@NAME="host"]/@VALUE'/> </li>
      </ul>
   </xsl:for-each> 

  </xsl:template>
</xsl:stylesheet>

This is my xml :

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="trans-simple.xsl" type="text/xsl"?>
<db>
<OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host1" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="1.1.1.1" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host2" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="1.1.1.1" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host3" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="3.3.3.3" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host4" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="4.4.4.4" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host5" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="1.1.1.1" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host7" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="1.1.1.1" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host8" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="2.2.2.2" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  <OBJECT>
    <PROPERTY NAME="__type"
    VALUE=".com.enterprise.dns.host_address" />
    <PROPERTY NAME="rrset_order_position" VALUE="0" />
    <PROPERTY NAME="host"
    VALUE="host9" />
    <PROPERTY NAME="is_ipv4" VALUE="true" />
    <PROPERTY NAME="address" VALUE="2.2.2.2" />
    <PROPERTY NAME="v6_prefix" VALUE="" />
    <PROPERTY NAME="configure_for_dhcp" VALUE="false" />
  </OBJECT>
  </db>
  • 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-26T10:47:47+00:00Added an answer on May 26, 2026 at 10:47 am

    The technique you are trying to use is called Muenchian grouping. You are trying to group your ‘host’ properties, by the ‘address’ property.

    Firstly, you have defined the key correctly, although in this case it could be simplified to the following if your XML didn’t contain PROPERTY elements under differently named elements

    <xsl:key name="same-ip" match="PROPERTY[@NAME='address']" use="@VALUE"/>
    

    The next stage in Muenchian grouping is to loop through the first element in each group (In your case, the first ‘host’ propertry for each ‘address’ property). This will get you your distinct groups.

    This is how it should be written:

    <xsl:for-each 
      select="db/OBJECT/PROPERTY
        [@NAME='address']
        [generate-id(.)=generate-id(key('same-ip',@VALUE)[1])]">
    

    Actually, it is better practise to use xsl:apply-templates in this case, rather than a xsl:for-each

    Then, you just need to loop through all the matching elements in the same group, which can be done be using the key

    <xsl:apply-templates select="key('same-ip', @VALUE)">
    

    Here is the final XSLT. Note I am using xsl:apply-templates here rather than a xsl:for-each

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:key name="same-ip" match="PROPERTY[@NAME='address']" use="@VALUE"/>
    
       <xsl:template match="/">
          <HTML>
             <HEAD>
                <TITLE>Template</TITLE>
             </HEAD>
             <BODY BGCOLOR="#FFFFFF">
                <xsl:apply-templates 
                  select="db/OBJECT/PROPERTY
                    [@NAME='address']
                    [generate-id(.)=generate-id(key('same-ip',@VALUE)[1])]" mode="group"/>
             </BODY>
          </HTML>
       </xsl:template>
    
       <xsl:template match="PROPERTY[count(key('same-ip', @VALUE)) &gt; 1]" mode="group">
          <ul>
             <li>
                <xsl:value-of select="@VALUE"/>
             </li>
             <xsl:apply-templates select="key('same-ip', @VALUE)"/>
          </ul>
       </xsl:template>
    
       <xsl:template match="PROPERTY">
          <li>
             <xsl:value-of select="../PROPERTY[@NAME='host']/@VALUE"/>
          </li>
       </xsl:template>
    </xsl:stylesheet>
    

    When this is applied to your given XML, the following is output

    <HTML>
       <HEAD>
          <TITLE>Template</TITLE>
       </HEAD>
       <BODY BGCOLOR="#FFFFFF">
          <ul>
             <li>1.1.1.1</li>
             <li>host1</li>
             <li>host2</li>
             <li>host5</li>
             <li>host7</li>
          </ul>
          <ul>
             <li>2.2.2.2</li>
             <li>host8</li>
             <li>host9</li>
          </ul>
       </BODY>
    </HTML>
    

    Do note the following line, which matches the first element in each group

    <xsl:template match="PROPERTY[count(key('same-ip', @VALUE)) &gt; 1]" mode="group">
    

    I had assumed from your given result, you wanted to ignore groups with one element (i.e. ‘Address’ Properties, with only one ‘host’ property). If this is not the case, simply change it to the following to output everything:

    <xsl:template match="PROPERTY" mode="group">
    

    Also note the use of the mode attribute to avoid the first template calling itself recursively which would lead to a stack overflow.

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

Sidebar

Related Questions

When I try to use the code below I get a duplicate variable error
I try get the mp3 flash player to work with my javascript on all
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
I try to get this code running. I am almost there but I got
server removes duplicate slashes from url, if i try to get http://mysite.com/a//b/ with .htaccess:
I try to get to a page straight from Bash at http://www.ocwconsortium.org/ . The
I try to get all WPF window controls collections. In other words i try
I try to get the name of executable name of all of my launched
I try to get the last modification date of a file: NSFileManager *fm =
When I try to get the eventinfo of a WPF 'rectangle', if the routedEvent

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.