This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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



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@ITCC.ws
> 
> 
> 
> ___________________________________________________________________
> 
> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]