Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: DOM / XPath / Reverse axis?

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 5/2/2007 3:32:00 PM

If you use SelectSingleNode on a reverse axis it gets the closest node to 
the context. If you use SelectNodes you then have a NodeList which contains 
the nodes in document order.

-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name


"Francesca Baslen" <francesca.baslen@g...> wrote in message 
news:46389d0e$0$446$426a74cc@n......
> OK, I found an answer myself. Not why my code behaves like this, but how 
> to get it do what what I want.
> Obviously, the SelectSingleNode method doesn't follow the reverse axis, 
> but SelectNodes does.
>
> Set Nodes2 = 
> Node1.SelectNodes("ancestor-or-self::*[@xml:lang][1]/@xml:lang")
> If Not(Nodes2.Length = 0) Then
> Response.Write "Lang:" & Nodes2(0).Text
> Response.Write " (inherited from " & 
> Nodes2(0).SelectSingleNode("..").NodeName & ")"
> End If
>
> Strange enough though.
>
> F
>
>
> Francesca Baslen was caught writing:
>> Hello,
>>
>> Suppose I want to write a custom function which for a given node Node1 
>> retrieves its language value (given by an xml:lang attribute).
>> This value can be inherited -- in which case the significant language 
>> value should be that of the closest ancestor which explicitly states a 
>> language value.
>>
>> Please take a look at my example ASP code below:
>>
>>
>> <%@ LANGUAGE = "VBScript" %>
>> <% Response.Buffer = True %>
>> <%
>> Dim XML1,XMLDoc1,Node1,Node2
>> Set XMLDoc1 = Server.CreateObject("MSXML2.DOMDocument")
>> XMLDoc1.setProperty "SelectionLanguage","XPath"
>> XMLDoc1.Async = False
>>
>> XML1 = XML1 & "<doc xml:lang=""de"">"
>> XML1 = XML1 & "<block xml:lang=""en"">"
>> XML1 = XML1 & "<item>Item</item>"
>> XML1 = XML1 & "</block>"
>> XML1 = XML1 & "</doc>"
>>
>> XMLDoc1.LoadXML(XML1)
>>
>> Set Node1 = XMLDoc1.SelectSingleNode("//item")
>> Set Node2 = Node1.SelectSingleNode("ancestor-or-self::node()/@xml:lang")
>>
>> If Not(Node2 Is Nothing) Then
>>     Response.Write "Lang:" & Node2.Text
>>     Response.Write " (inherited from " & 
>> Node2.SelectSingleNode("..").NodeName & ")"
>> End If
>>
>> Set Node1 = Nothing
>> Set Node2 = Nothing
>> Set XMLDoc1 = Nothing
>> %>
>>
>> On this example, the XML document is made up of 3 nested nodes "doc", 
>> "block", "item". "doc" and "block" have different xml:lang values.
>> I want to test the language value of the node "doc" (Node1)
>> In my understanding, the XPath expression 
>> "ancestor-or-self::node()/@xml:lang" applied to Node1 is the correct one. 
>> As an argument of the XML DOM SelectSingleNodemethod, it *should* select 
>> the first node on the reverse axis, ie the @xml:lang of the "block" node.
>>
>> Problem: instead of the expected behaviour, it selects the @xml:lang of 
>> the "doc" node (indeed the first node, but in the document order, *not* 
>> the reverse order going from "item" upwards), and I don't understand why.
>>
>> Could somebody explain this behaviour and help me solve this problem.
>>
>> Thanks,
>>
>> F
>> 




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