Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - DOM / XPath / Reverse axis? >Thread Next - Re: DOM / XPath / Reverse axis? Re: DOM / XPath / Reverse axis?To: NULL Date: 5/2/2007 4:16:00 PM
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
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
