XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Neal WaltersSubject: Using Xpath against Variables (that contain nodes)
Author: Neal Walters
Date: 17 Jul 2006 02:49 PM
I'm trying to do a quick elegant solution. I have an existing XSLT that maps from an "OriginalProfile", and now everwhere we reference that, I need to map from one of two different profiles.

May idea was to created a variable called "UseThisProfile" one time, then this would make changes to the rest of the XSLT very easy.

<xsl:variable name="UseThisProfile">
<xsl:choose>
<xsl:when test="(//*[local-name()='ConstituentReconcileRequest']/*[local-name()='Profile'])">
<xsl:copy-of select="//*[local-name()='ConstituentLocateResponse']/*[local-name()='Profile']"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="//*[local-name()='ConstituentLocateResponse']/*[local-name()='OriginalProfile']/*[local-name()='Profile']"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

... code omitted here ...



<xsl:element name="ult:LocalVariable">
<xsl:attribute name="VarName">gOrigAddress2</xsl:attribute>
<xsl:element name="ult:VarValue">
<xsl:copy-of select="$UseThisProfile/*[local-name()='Profile']/*[local-name()='Address2']"/>
</xsl:element>
</xsl:element>


The error I'm getting is "Expression must evaulate to a node-set".
It gives no line number, but it's the line that has the variable $UseThisProfile followed by more Xpath.

Is it possible to combine a variable with more Xpath?
Or how can I apply Xpath to the nodes in a variable?

We are in User Acceptance Testing and I hope to have this fixed by a BUILD that is due this afternoon.

Thanks,
Neal

Postnext
Neal WaltersSubject: Using Xpath against Variables (that contain nodes)
Author: Neal Walters
Date: 17 Jul 2006 03:16 PM
I'm trying the msxsl:node-set extension.

I think this will do it - I'm testing now:

<xsl:copy-of select="msxsl:node-set($UseThisProfile)/*[local-name()='Profile']/*[local-name()='Address1']"/>





Postnext
Neal WaltersSubject: Using Xpath against Variables (that contain nodes)
Author: Neal Walters
Date: 17 Jul 2006 03:20 PM
It seems to work - but it gives me a lot of ugly repeated namespaces:


<ult:LocalVariable VarName="gOrigAddress1">
<ult:VarValue>
<Address1 xmlns="http://schemas.microsoft.com/BizTalk/2003/aggschema" xmlns:pr="http://schemas.compassion.com/constituent/profile/profile/2005-03-01" xmlns:ns0="http://schemas.compassion.com/constituent/locateresponse/2005-10-01"
xmlns:cnm="http://schemas.compassion.com/constituent/nearmiss/2005-10-01" xmlns:ns1="http://schemas.compassion.com/common/updaterecord/2005-03-01" xmlns:ex="http://schemas.compassion.com/common/exceptions/2005-03-01"
xmlns:ad="http://schemas.compassion.com/common/address/2005-03-01">109 Woodrun Cir</Address1>
</ult:VarValue>
</ult:LocalVariable>

It's really hard to see the address buried under all those namespaces, but I think it will work.

Any other ideas appreciated.


Postnext
Neal WaltersSubject: Using Xpath against Variables (that contain nodes)
Author: Neal Walters
Date: 17 Jul 2006 03:27 PM
I'm having a fun conversation with myself here... <grin>

I added the /text() at the end - and now it looks a lot cleaner:

<xsl:copy-of select="msxsl:node-set($UseThisProfile)/*[local-name()='Profile']/*[local-name()='Address1']/text()"/>

Results in:

<ult:LocalVariable VarName="gOrigAddress1">
<ult:VarValue>109 Woodrun Cir</ult:VarValue>
</ult:LocalVariable>

Neal

Postnext
Ivan PedruzziSubject: Using Xpath against Variables (that contain nodes)
Author: Ivan Pedruzzi
Date: 17 Jul 2006 03:39 PM


Out of curiosity why you use a generic XPath expression form like

<xsl:copy-of select="msxsl:node-set($UseThisProfile)/*[local-name()='Profile']/*[local-name()='Address1']/text()"/>

When is XSLT you can declare the namespace and then use a more compact form like

<xsl:copy-of select="msxsl:node-set($UseThisProfile)/myns:profile/myns:Address1/text()"/>



Ivan Pedruzzi
Stylus Studio Team

Postnext
Neal WaltersSubject: Using Xpath against Variables (that contain nodes)
Author: Neal Walters
Date: 17 Jul 2006 05:03 PM
Several reasons. One, I'm starting with someone elses code. Two, we use Stylus Studio to generate the XPath for us (the ol' right-click generate Xpath). Three, originally this was a Biztalk Map with XSLT custom functoids. I don't think Biztalk provides a way to add the namespaces.

In this case, I did so much surgery, I did convert it to an entirely XSLT stylesheet (it will still go to a Biztalk map, but can now be developed, tested, and re-formatted in Stylus Studio). To me, it's much easier to test/develop this way, if over 1/2 the Biztalk map is custom XSLT functoids anyway.

Basically a custom XSLT functoid is where you use Biztalk mapping to do the map, but "occassionally" need the powerful features of XSLT. Custom Functoids are very hard to do in Biztalk, they give you a tiny editor window that cannot be resized, and there is no edit checking at all as you type.

Neal



Postnext
Ivan PedruzziSubject: Using Xpath against Variables (that contain nodes)
Author: Ivan Pedruzzi
Date: 17 Jul 2006 06:01 PM
Hi Neal,

The tree View in the XML Editor used to create a generic XPath expression form because the XPath evaluator did not allow to manage namespaces.
Starting from 2006 R3 the generated XPath expression uses the compact form and the XPath evaluator allows to manage the namespaces prefixes.

If you already migrated to a standalone XSLT and from what I gather you can ask BizTalk to link directly to external XSLT you are no more constrained to use a subset of language.

I apology If I misunderstood you.

Ivan Pedruzzi
Stylus Studio Team

Postnext
Neal WaltersSubject: Using Xpath against Variables (that contain nodes)
Author: Neal Walters
Date: 18 Jul 2006 10:46 AM

Yes, I have played with the new XQuery editor. However, when you right-click "Copy XPath Query to Clipboard" it builds the full syntax with all the "local-name()" phrases in it. You then have to spend time to "simplify" it by adding the namespaces, correct?

Perhaps the ideal feature is when you right click "Copy XPath Query to Clipboard" (while in your sample XML file), it would prompt you for an XSLT file name, then it could read that XSLT and build an XQuery that would be compatible with the specific namespaces in that XSLT. This is because you could have two different XSLT's with totally different namespaces prefixes. The only "safe" and "full compatible" XQuery is the verbose fully-qualfieid one.

I agree that "I am no longer constrained", but it's one of those cases where it is working, and I'm not the time spent to "pretty it up" is really worth the time.

As usual, thanks for you ideas.






Posttop
Ivan PedruzziSubject: Using Xpath against Variables (that contain nodes)
Author: Ivan Pedruzzi
Date: 18 Jul 2006 11:49 AM

Sorry I was incorrect, the XPath evaluator still generates the absolute form when namespaces are involved.

Yes we agree with you, having a smart Paste functionality in the XSLT/XQuery editor is in our plans.

Ivan Pedruzzi
Stylus Studio Team

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.