[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: <xsl:for-each select> and acessing the parent tag'

Subject: Re: <xsl:for-each select> and acessing the parent tag's attribute
From: cutlass <cutlass@xxxxxxxxxxx>
Date: Sun, 15 Apr 2001 15:19:53 +0100
xsl for each select

Priya Pinto wrote:


Hi,

I want to know how to get the value of the parent tag when you are in an
<xsl:for-each select> of the child tag

Here is an illustration of what I want

this is the xml file

Hello,


i added another <region> xml element to make sure test was a bit more complete.

there are various methods of doing this transformation, but this is a good start.

here is the xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="//City">
<row>
<country><xsl:value-of select="ancestor::Country/@Name"/></country>
<region><xsl:value-of select="parent::Region/@Name"/></region>
<city><xsl:value-of select="@Name"/></city>
</row>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------------------


here is the xml

<?xml version="1.0" encoding="UTF-8"?>
<World>
  <Country Name="Afghanistan">
      <Region Name="Herat">
          <City Name="Herat"></City>
      </Region>
      <City Name="Kabul"></City>
      <City Name="Kandahar"></City>
      <City Name="Mazar-e Sharif"></City>
  </Country>
  <Country Name="Albania">
      <City Name="Shkoder"></City>
      <Region Name="test">
      <City Name="Tirane"></City>
      </Region>
  </Country>
</World>


---------------------------------------------------------


regards, Jim Fuller



<?xml version="1.0" encoding="UTF-8"?>
<World>
<Country Name="Afghanistan">
<Region Name="Herat">
<City Name="Herat"></City>
</Region>
<City Name="Kabul"></City>
<City Name="Kandahar"></City>
<City Name="Mazar-e Sharif"></City>
</Country>
<Country Name="Albania">
<City Name="Shkoder"></City>
<City Name="Tirane"></City>
</Country>
</World>

The XSL code

<xsl:for-each select="World/Country/City">
<row>
<country><xsl:value-of select="World/Country/@Name"/></country>
<region><xsl:value-of select="Region/@Name"/></region>
<city><xsl:value-of select="Region/City/@Name"/></city>
</row>

This code does not give me the required result.

Thanks
Priya
Sincerely,

Priya Ann Pinto
Software Engineer - Java
Email : Priya.P@xxxxxxx



___________________________________________________________________

ITCC FZ L.L.C
P.O. Box 74500
Dubai, United Arab Emirates
Phone   : +971 4 330 3778
Fax     : +971 4 330 3779
Website : http://www.ITCC.ws

This message and any attachments are confidential to the ordinary
user of the email address to which it is addressed and may also be
legally privileged. If you are not the intended recipient, the
printing, copying, forwarding, disclosure, or use of any part of this
message or its attachments is strictly prohibited, and may be
unlawful. If you have received this message in error, please inform
the sender immediately by return e-mail and then promptly delete
it from your system.

We strongly recommend that you read the complete version of this
confidentiality note and disclaimer, available on our website at
http://www.ITCC.ws/email_disclaimer.html

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list





XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.