Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xslt different levels

From: "tshad" <tshad@----------.--->
To: NULL
Date: 1/9/2008 12:36:00 PM


"Anthony Jones" <Ant@y...> wrote in message 
news:en8DSmeUIHA.4532@T......
> "tshad" <tshad@d...> wrote in message
> news:eu9R3$XUIHA.5816@T......
>> If I have the following xml:
>>
>> <?xml version="1.0"?>
>> <addresses>
>>     <address country="Italy">
>>         <tag name="street" flag="5">One Microsoft Way</tag>
>>         <tag name="number">1</tag>
>>         <tag name="city">Redmond</tag>
>>         <tag name="state" unit="25">WA</tag>
>>         <tag name="zip">98052</tag>
>>     </address>
>>     <address country="France">
>>          <section type="Condo" Comp="1">
>>               <tag name="street">15 Mako Place</tag>
>>               <tag name="number">1545</tag>
>>               <tag name="city">Fargo</tag>
>>               <tag name="state" unit="10">Paris</tag>
>>               <tag name="zip">10110</tag>
>>          </section>
>>     </address>
>> </addresses>
>>
>> Where one section is addresses/address/tag and another is
>> addresses/address/section/tag, I want to be able to get the country from
> the
>> address.
>>
>> Nomrally I would just do
>>
>> <xsl:value-of select="ancestor::address/@country"/>
>>
>> But if I have a "section", I would need to go up 2 levels.
>>
>> My current xsl is:
>>
>> <xsl:stylesheet version="1.0"
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>    <xsl:output method="xml" indent="yes"/>
>>    <xsl:template match="addresses">
>>         <dataset>
>>              <xsl:apply-templates/>
>>         </dataset>
>>    </xsl:template>
>>  <xsl:template match="tag|section/tag">
>>      <address>
>>           <sectionNumber>
>>                 <xsl:value-of select="ancestor::section/@Comp"/>
>>            </sectionNumber>
>>            <name>
>>                   <xsl:value-of select="@name"/>
>>            </name>
>>            <flag>
>>                 <xsl:if test="not(@flag)">
>>                       <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>                 </xsl:if>
>>                 <xsl:value-of select="@flag"/>
>>            </flag>
>>           <unit>
>>                 <xsl:if test="not(@unit)">
>>                        <xsl:attribute name="xsi:nil">true</xsl:attribute>
>>                 </xsl:if>
>>                 <xsl:value-of select="@unit"/>
>>           </unit>
>>          <value>
>>               <xsl:value-of select="."/>
>>          </value>
>>      </address>
>>  </xsl:template>
>> </xsl:stylesheet>
>>
>> I would like to add a section:
>>
>>           <country>
>>                 <xsl:value-of select="ancestor::address/@country"/>
>>            </country>
>>
>> but this won't work for both cases.
>>
>
>
> Why not?
>
> I think you are confusing ancestor:: with parent:: .  The current tag node
> whether it be a child of section or address will have an ancestor of
> address.
>
You're right, I was.

Thanks,

Tom
> -- 
> Anthony Jones - MVP ASP/ASP.NET
>
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent