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 June 30th, 2008, 05:00 AM
Authorized User
 
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Building a new XML > lost in copy-of-select and if

I need to create another XML similar to my source XML but I will have to test whether three child nodes contains specific information as follows

  Qual_A = Data A and
  Qual_B = Data B and
  Qual_C = Data C

So the resulting XML will contain rows 1, 3 and 4 only

Finding the row using Xpath below is not a problem

  //column[@name='Qual_A']/text()='Data A' and column[@name='Qual_B']/text()='Data B' and column[@name='Qual_C']/text()='Data C'

But I'm lost in using the following XSLT instructions to build the XML

- copy
- copy-of-select + xpath above
- if + xpath above



Thanks for the usual support!


==========
source XML
==========

<row>
 <column name="Qual_A">Data A</column>
 <column name="Qual_B">Data B</column>
 <column name="Qual_C">Data C</column>
 <column name="Qual_D">Get Me First</column>
</row>
<row>
 <column name="Qual_A">Data A</column>
 <column name="Qual_B">Data B</column>
 <column name="Qual_C">Data B</column>
 <column name="Qual_D">Data B</column>
</row>
<row>
 <column name="Qual_A">Data A</column>
 <column name="Qual_B">Data B</column>
 <column name="Qual_C">Data C</column>
 <column name="Qual_D">Get Me Second</column>
</row>
<row>
 <column name="Qual_A">Data A</column>
 <column name="Qual_B">Data B</column>
 <column name="Qual_C">Data C</column>
 <column name="Qual_D">Get Me Third</column>
</row>
.
.
.
.




 
Old June 30th, 2008, 05:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Finding the row using Xpath below is not a problem

  //column[@name='Qual_A']/text()='Data A' and column[@name='Qual_B']/text()='Data B' and column[@name='Qual_C']/text()='Data C'


that's right except for the initial "//" which means that you will succeed if there is a Qual A/Data A anywhere in the document, not just in the current row.

You can just use

<xsl:copy-of select="row[column[@name='Qual_A']/text()='Data A' and column[@name='Qual_B']/text()='Data B' and column[@name='Qual_C']/text()='Data C'
]"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 30th, 2008, 07:35 AM
Authorized User
 
Join Date: Jun 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Thanks for noting the issue on using '//'...

My problem earlier was I introduced too much instructions on XSLT (copy/copy of select/ if /apply templates select/ etc...) when all I need is a simple solution that requires 2 lines of XSLT code.

Cheers!











Similar Threads
Thread Thread Starter Forum Replies Last Post
Mutiple <select..> with XML problem ousys .NET Framework 2.0 0 November 11th, 2007 03:37 AM
Saving data into Xml file when connection is lost kondapallichandu C# 2005 1 October 10th, 2007 07:25 AM
Achitecture ? SQL -> XML -> ASP -> PDF or HTML Frm jstrong Classic ASP XML 0 July 9th, 2005 01:18 PM
HELP: XSL -> HTML <select selected=true> jedbartlett XSLT 4 October 7th, 2004 11:16 PM
asp(ado->xml) --->internet>--asp(xml->ado) moon XML 0 November 28th, 2003 09:27 AM





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