XPath

Here should go questions about transforming XML with XSLT and FOP.
forummarcel
Posts: 24
Joined: Wed Feb 13, 2013 9:54 am

XPath

Post by forummarcel »

Hello everyone

I have a question relative to the namespaces and the xpath-editor within oxygen. It appears that oxygen can not execute my xpath on attibutes of different namespaces:

Examples:
<title xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" id="topic_t3j_v35_nl" aid:pstyle="title1">1 My Title</title>

<p xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:pstyle="any_format"><li>List entry 1</li></p>

XPatch Expressions:
//@id : results as expected
//@aid: Error information: XPath doesn't return any results..

How i can achieve that i can equally run my xpath on any sort of attributes?

Have a good evening.
Marcel
Costin
Posts: 833
Joined: Mon Dec 05, 2011 6:04 pm

Re: XPath

Post by Costin »

Hello,

Oxygen tries to help the user with his XPaths, by using the default namespace of the root element.
This can be also noticed by going into the XPath options, either from the shortcut (gear like icon) in the XPath Toolbar, or by going into the oXygen's menu Options > Preferences > XML > XSLT-FO-XQuery > XPath.
In the same configuration page the user has the possibility to declare custom namespaces.

On the other hand, "aid" is not an attribute. It is even a namespace prefix, so this is why the XPath will not return valid results.
In case you need to search for attributes coming from any other namespaces (like "pstyle" in your case), you should use an instruction like:

Code: Select all

//@*:pstyle
Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support
forummarcel
Posts: 24
Joined: Wed Feb 13, 2013 9:54 am

Re: XPath

Post by forummarcel »

Hi Costin

Thanks for your hint. This made it work in the Xpath-Editor: //p[@*:pstyle='any_format']

However, when i integrate the same statement in my xsl-file and execute it, i get the following error-message:

"Invalid character (:) in expression //p[@*:pstyle='any_format']"

The statement that i used is the following:
<xsl:template match="//p[@*:pstyle='any_format']">
</xsl:template>

Any idea why this is not working?
Regards,
Marcel
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: XPath

Post by adrian »

Hi,

XSLT 1.0 does not allow this kind of expression in the template match pattern, it doesn't like the "any namespace prefix" (*). You can either:
- declare the specific namespace on the XSL root and use it in the expression:

Code: Select all

xmlns:myns="http://ns.adobe.com/AdobeInDesign/4.0/"

Code: Select all

<xsl:template match="//p[@myns:pstyle='any_format']">
or
- switch to XSLT 2.0. This means you have to change the version on the XSL root to "2.0" and use the Saxon 9 (HE/PE/EE) engine when applying the transformation.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply