Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Pattern problem

From: "tshad" <tshad@----------.--->
To: NULL
Date: 8/13/2008 9:08:00 AM


"Martin Honnen" <mahotrash@y...> wrote in message 
news:eXhB7bU$IHA.2060@T......
> tshad wrote:
>
>> ancestor::form/@name gives me 1007, as it should.  But I need to look at 
>> all the forms on the same level and get the one that has @primary = 
>> 'true' and use the @name of that form.
>>
>> Is this the wrong way to get that?
>>
>> Seems pretty straight forward.
>>
>> I assume the pattern in:
>>
>> <xsl:value-of select="ancestor::form[@primary='true']/@name"/>
>>
>> says to look for all the ancestor "form" tags and look at the one that 
>> one. I did notice that I had primary set in my program without the "@". 
>> But even after changing it to the above is not working.
>
> The sample XML you posted looks like this:
>
> <Report>
>   <appraisal>
>     <data>
>       <form name="1007" primary="false">
>         <section type="subject" number="0">
>           <tag name="GR_AGE.1" flags="1" format="4096">4 Yrs.</tag>
>         </section>
>       </form>
>       <form name="reffee" primary="false">
>           <tag name="FFHD_NFIP_COMMUNITY_NUMBER.1" flags="0"
> format="0">040040</tag>
>       </form>
>       <form name="1004_05" primary="true">
>         <section type="subject" number="0">
>           <tag name="PROP_PHYS_DEFICIENCIES_DESC.1" flags="4"
> format="4096">None apparent </tag>
>         </section>
>       </form>
>     </data>
>   </appraisal>
> </Report>
>
> In that sample each 'tag' element has just one ancestor element of the 
> name 'form'. However each such 'form' element has siblings so perhaps you 
> want
>  <xsl:value-of select="(
>   ancestor::form[@primary = 'true'] |
>   ancestor::form/preceding-sibling::form[@primary = 'true'] |
>   ancestor::form/following-sibling::form[@primary = 'true']
>   )[1]/@name"/>
> which looks at the sibling 'form' elements as well.
>
That worked perfectly.

Just a couple of questions.

Since I know that 1007 is not a primary form (as there is only one primary 
form), I assume I could just do:

<xsl:value-of select="(
   ancestor::form/preceding-sibling::form[@primary = 'true'] |
   ancestor::form/following-sibling::form[@primary = 'true']
   )[1]/@name"/>

Does ancestor::form look only at the direct ancesters - which is why it 
didn't find the siblings of the ancestor?

In ancestor::form/preceding-sibling::form, does it say:

Look at the ancestor named form then look at all the siblings named form 
that came before it (and the reverse for following-sibling)?

What does the [1] do?  Is this in case it passes back more than one result?

If there is only one result, do I need the [1]?

Thanks,

Tom
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




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