Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Need to get previous node

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 8/6/2009 10:44:00 AM
"tshad" <toms@p...> wrote in message 
news:#OCwMYfFKHA.6020@T......
>
> "Martin Honnen" <mahotrash@y...> wrote in message 
> news:OoVYXJfFKHA.4968@T......
>> tshad wrote:
>>> That did it, but now I need to use that number to get a field from a 
>>> previous set of nodes, but the select is not working.
>>>
>>> If I make the following changes the XML looks like:
>>>
>>>     <FORM>
>>>         <FIELDS>
>>>             <TITLE1>This is Title1</TITLE1>
>>>             <TITLE2>This is Title2</TITLE2>
>>>             <TITLE3>This is Title3</TITLE3>
>>>         </FIELDS>
>>>         <FORMPHOTOS>
>>>             <PHOTO NUM="1">
>>>                 <FILENAME>09May001.jpg</FILENAME>
>>>                 <FILETYPE>JPEG</FILETYPE>
>>>             </PHOTO>
>>>             <PHOTO NUM="2">
>>>                 <FILENAME>09005.jpg</FILENAME>
>>>                 <FILETYPE>JPEG</FILETYPE>
>>>             </PHOTO>
>>>             <PHOTO NUM="3">
>>>                 <FILENAME>09002.jpg</FILENAME>
>>>                 <FILETYPE>JPEG</FILETYPE>
>>>             </PHOTO>
>>>         </FORMPHOTOS>
>>>     </FORM>
>>>
>>> I am doing:
>>>
>>>  <xsl:template match="FORMPHOTOS/PHOTO">
>>>   <xsl:choose>
>>>    <xsl:when test=". != ''">
>>>     <attachment>
>>>      <source>
>>>       <xsl:value-of select="../../FIELDS/*[name() = 
>>> concat('TITLE',@NUM)]"/>
>>
>> Inside of the square brackets the context node is no longer the PHOTO 
>> element but rather that * child element. So you either need to store the 
>> attribute value in a variable and use that variable e.g.
>>    <source>
>>      <xsl:variable name="n" select="@NUM"/>
>>      <xsl:value-of select="../../FIELDS/*[name() = concat('TITLE',$n)]"/>
>>
>> or you can use the current() function e.g.
>>    <source>
>>      <xsl:value-of select="../../FIELDS/*[name() = 
>> concat('TITLE',current()/@NUM)]"/>
>> as that refers to the node currently processed by an xsl:for-each or 
>> xsl:apply-templates.
>>
> Worked perfectly.
>
> When you say current node, are you talking about everything inside the 
> PHOTO tags?
>
Yes, you matched the FORMPHOTOS/PHOTO element so the context node is PHOTO.
But once you 'start down' an XPath the context changes to whatever the XPath 
selects, to refer back to the node that was the context use the current() 
function. Before any XPaths are followed, such immediately inside the 
template the current node and the context nod are equal:

<xsl:template match="FORMPHOTOS/PHOTO">
<!-- here current node equals context node -->
</xsl:template>
> Or FORMPHOTOS as well.  In otherword, if I change the FORMPHOTOS element 
> to:
>
> <FORMPHOTOS LABEL="HOUSE">
>
> Could I have also accessed the LABEL as:
>
>   <source>
>     <xsl:value-of select="@HOUSE"/>

Yes

>
> When you say that "Inside of the square brackets the context node is no 
> longer the PHOTO element but rather that * child element", what is the * 
> child element refering to?
>
> Thanks,
* means all the child elements.
>
> Tom
>>
>>
If I may suggest you get hold of Michael Kay's latest book on XSLT, it's not 
really one of those languages you can pick up as you go along; a few hours 
spent on the basics will reap much reward and pay for itself in no time.

Regards

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name 



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