Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


DOM / XPath / Reverse axis?

From: Francesca Baslen <francesca.baslen@-----.--->
To: NULL
Date: 5/2/2007 3:42:00 PM

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