p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2006, 05:32 AM
Authorized User
Points: 204, Level: 4
Points: 204, Level: 4 Points: 204, Level: 4 Points: 204, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: Haarlem, , Netherlands.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Testing tree structure

I would like to know if there is a quick way with xslt to check if an element in a xml document is at a valid position in the element tree structure defined in the xsd schema?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 16th, 2006, 05:42 AM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

Not really.

With a schema-aware stylesheet in XSLT 2.0 you can validate a document (or any subtree) against a schema, but the effect is a fatal error if the document is invalid, which doesn't seem to be what you are looking for.

Perhaps you could explain the background to the requirement.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 16th, 2006, 08:06 AM
Authorized User
Points: 204, Level: 4
Points: 204, Level: 4 Points: 204, Level: 4 Points: 204, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: Haarlem, , Netherlands.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to test the hierarchy of all elements in the xml tree in a non schema aware processor.
I can check it with an external document (doctree.xml)with all the paths in it(generated from the xsd) so I could test the path as stringvalue for every element

I build the path string with the expression
concat('//',string-join(for $i in (ancestor-or-self::node()[name()]) return $i/local-name(),'/'))

I now can search the elementtree in the xml like:
select="if doc('doctree.xml')//path[.= concat('//',string-join(for $i in (ancestor-or-self::node()[name()]) return $i/local-name(),'/'))])"

but this seems to be a bit too complicated to me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 16th, 2006, 08:23 AM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

You need to explain the requirement more clearly.

You have a set of possible paths in some file doctree.xml, yes? And you now want to test whether one of these paths matches some other document, say instance.xml?

Your proposed expression if doc('doctree.xml')//path[.= concat('//',string-join(for $i in (ancestor-or-self::node()[name()]) return $i/local-name(),'/'))]) works entirely within a single document, so it's not clear what it's trying to achieve.

Do you want to know whether all the paths in doctree have a match, or whether a specific one does, or whether a particular node in instance.xml matches one of the paths, or what???

Instead of generating a data file containing paths, why not generate an XSLT stylesheet or XQuery that gives you the answer directly?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old November 16th, 2006, 09:23 AM
Authorized User
Points: 204, Level: 4
Points: 204, Level: 4 Points: 204, Level: 4 Points: 204, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: Haarlem, , Netherlands.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I want to test if a path of a particular node in instance.xml matches the value of a <path> element in paths.xml

like this:
instance.xml
<elementA><elementB>Value of B</elementB></elementA>

paths.xml
<paths>
    <path>//elementA</path>
    <path>//elementA/elementB</path>
</paths>
when I want to test element B I'll test the string value "//elementA/ElementB"
when I find this value in the paths.xml//paths/path its OK
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old November 16th, 2006, 09:41 AM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

I'd suggest that instead of generating paths.xml as data, you generate

<xsl:template match="//elementA" mode="test"/>
<xsl:template match="//elementA/elementB" mode="test"/>
<xsl:template match="*" mode="test">NO MATCH</xsl:template>

and import this into your stylesheet. You can then test element B as

<xsl:variable name="x">
  <xsl:apply-templates mode="test"/>
</xsl:variable>
<xsl:if test="$x = 'NO MATCH'">...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old November 16th, 2006, 10:11 AM
Authorized User
Points: 204, Level: 4
Points: 204, Level: 4 Points: 204, Level: 4 Points: 204, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: Haarlem, , Netherlands.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great, thanx this is what helps me a lot. I already had tried it with the * path description but I didn't use it in combination with mode and variable. Now only hoping I don't have recursive elements
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Tree Structure Problem KLam BOOK: Beginning InfoPath 2003 1 August 5th, 2007 12:44 PM
XML Tree Structure Problem KLam BOOK: Professional InfoPath 2003 0 July 26th, 2007 09:35 AM
Need help with tree data structure vidhya_venkat C++ Programming 0 June 14th, 2006 02:13 PM
tree data structure pandjie Java Basics 1 January 16th, 2006 05:15 AM
Creating a Tree Structure pazzuzu C++ Programming 2 February 26th, 2005 12:07 PM



All times are GMT -4. The time now is 12:59 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc