I go to tree view, right click, choose "Copy xpath query to clipboard"
and it generates xpath of: /DocumentProcessingInfo/documentProcessingStatus,
which yields 0 hits when I run it.
If I cannot remove the namespace (and cannot add a prefix to it),
how do I build proper Xpath query and why can't Stylus Studio build
query for me? Two of us spent 45 minutes last night working on
this and finally gave up. We tried a few variations using the
"local-name" keyword.
We are using Stylus Studio to help us with our Biztalk 2004 implementation.
Below is a similar post I sent to Microsoft newsgroup. The short xpath is
about 45 characters in length but doesn't work. The correct xpath is
about 150 characters long and very confusing. We would like to use
Stylus Studio to build the Xpath that works.
// Not sure why shorted Xpath does not work here...
//vXpath =
"/ns0:Order/ns0:ShipMethod-15[1]/@ShipMethodID";
Subject:Re: Xpath when namespace present Author:(Deleted User) Date:23 Nov 2004 01:56 AM
Hi Neal,
thanks for reporting this: Stylus should definitely create the correct
XPath string also when a default namespace is declared midway in the document.
A fix for this will be in the next update of Stylus.
Should I be able to build an XPath something like this?
I don't really understand it - but it's more or less the way Biztalk 2004 generates Xpath for its schemas.
/*[local-name()="DocumentProcessingInfo" and namespace-uri()='']/*[local-name()="documentProcessingStatus" and namespace-uri()='']
Stylus Studio finds 0 hits whereas I am hoping to find the documentProcessingStatus node.
XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
/TestSchema/CGroup/CChild1 CChild1Value
Sample 2 – Simple Data with prefixed namespace
NOTE: When you generate test xml data from a Biztalk schema, it generates it as follows with the “ns0” prefix used on the namespace.
XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/A AValue
/ns0:TestSchema/B BValue
/ns0:TestSchema/CGroup/CChild1 CChild1Value
Biztalk Distinguished Field have xpath like this:
Sample 4 – Prefixed Namespace (not prefixed elements)
One quick solution to using complicated Xpath names is to put a prefix on the namespace. The namespace is no longer the “default namespace” and now only applies to element specifically prefixed with ns0.
XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
Sample 5 – Obscure Sample
This shows how you could have two namespaces with different prefixes, and use the namespace-uri() keyword instead of the namespace prefix.
<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema" xmlns:x="testx">
<A>AValue</A>
<x:B>BValue</x:B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>
<!--
Works: /ns0:TestSchema/x:B
Works: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx']
-->
XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/x:B BValue
/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx'] BValue
XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
/TestSchema/CGroup/CChild1 CChild1Value
Sample 2 – Simple Data with prefixed namespace
NOTE: When you generate test xml data from a Biztalk schema, it generates it as follows with the “ns0” prefix used on the namespace.
XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/A AValue
/ns0:TestSchema/B BValue
/ns0:TestSchema/CGroup/CChild1 CChild1Value
Biztalk Distinguished Field have xpath like this:
Sample 4 – Prefixed Namespace (not prefixed elements)
One quick solution to using complicated Xpath names is to put a prefix on the namespace. The namespace is no longer the “default namespace” and now only applies to element specifically prefixed with ns0.
XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
Sample 5 – Obscure Sample
This shows how you could have two namespaces with different prefixes, and use the namespace-uri() keyword instead of the namespace prefix.
<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema" xmlns:x="testx">
<A>AValue</A>
<x:B>BValue</x:B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>
<!--
Works: /ns0:TestSchema/x:B
Works: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx']
-->
XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/x:B BValue
/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx'] BValue
XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
/TestSchema/CGroup/CChild1 CChild1Value
Sample 2 – Simple Data with prefixed namespace
NOTE: When you generate test xml data from a Biztalk schema, it generates it as follows with the “ns0” prefix used on the namespace.
XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/A AValue
/ns0:TestSchema/B BValue
/ns0:TestSchema/CGroup/CChild1 CChild1Value
Biztalk Distinguished Field have xpath like this:
Sample 4 – Prefixed Namespace (not prefixed elements)
One quick solution to using complicated Xpath names is to put a prefix on the namespace. The namespace is no longer the “default namespace” and now only applies to element specifically prefixed with ns0.
XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
Sample 5 – Obscure Sample
This shows how you could have two namespaces with different prefixes, and use the namespace-uri() keyword instead of the namespace prefix.
<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema" xmlns:x="testx">
<A>AValue</A>
<x:B>BValue</x:B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>
<!--
Works: /ns0:TestSchema/x:B
Works: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx']
-->
XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/x:B BValue
/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx'] BValue