Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2008, 09:51 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Compound Select Statements

I'm running Saxon 9

I am trying to find an element that has specific values for a couple of child elements, B where C = 1 and D = 3.

A - B - C = 1
      + D = 2
  + B - C = 1
      + D = 3
  + E

My current node is E
My select statement is

select = "//B[./C = 1][./D = 3]"

I've also tried

select = "//B[(./C = 1) and (./D = 3)]

neither is giving the answer I want (the second 'B' node) I tend to get neither node.

While I try to find a typo somewhere causing this, are these valid ways find this node?



------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old October 14th, 2008, 09:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Both your expressions look correct to me.

Perhaps it would be better if you showed actual XML source, and perhaps a complete stylesheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 14th, 2008, 10:14 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Thanks Michael.

As it turned out it was a typo. I had a trailing space after one of the values for my keys.

My complete stylesheet is over 3500 lines long. My XML files are over 2500 lines long, each and there are 12 of these (so far). I hesitate to post entire files when I have these issues, that's why I try to simplify the problem to the representative tree.

I more than appreciate the offer to examine the entire stylesheet, and if I find myself in a spot that I cannot solve, I may take you up on that offer.

Thanks again!






------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old October 14th, 2008, 10:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You definitely don't want to be posting things that long. But cutting it down to something that's executable is often better than cutting it down to fragments that aren't - we want to know that the bug hasn't been removed in the course of cutting it down.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 14th, 2008, 10:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

As per my understanding, if your input xml is somewhat like
<?xml version="1.0" encoding="ISO-8859-1"?>
<A>
    <B>
        <C>1</C>
        <D>2</D>
    </B>
    <B>
        <C>1</C>
        <D>3</D>
     </B>
    <E>test</E>
</A>

and your current template match is for "E", then try the below code to select only B where C = 1 and D = 3:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" indent="yes"/>


    <xsl:template match="E">
        <xsl:value-of select="../B[C = 1][D = 3]"></xsl:value-of>
    </xsl:template>
    <xsl:template match="C"/>
    <xsl:template match="D"/>
</xsl:stylesheet>


Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using COLLATE in SQL SELECT Statements sudhakaratp SQL Server 2000 8 September 6th, 2018 01:16 PM
code on page 218 two select statements in one uvis130 BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 0 September 3rd, 2007 06:56 AM
How to capture compound keypress, e.g. Ctrl-P gelias VB How-To 2 October 25th, 2006 12:04 PM
Case Select Statements & Updating the Database jackiew General .NET 1 April 11th, 2006 11:47 AM
IF ELSE statements gmpurple Classic ASP Databases 4 November 15th, 2004 04:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.