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 July 20th, 2006, 12:41 PM
Authorized User
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default seperate errored records from xml using xslt

I have a source xml for student which contains all the student record.
<Data>
  <Student>
    <Name>Tom</Name>
    <Age>12</Age>
    <SSN>121-12-1234</SSN>
  </Student>
  <Student>
    <Name></Name>
    <Age>13</Age>
    <SSN>123-12-1232</SSN>
  </Student>
</Data>

I need to check data inside xml and based on that i have to seperate correct records and errored records.My output xml will contain 2 section 1 is corrected one and another one is errored one records.
My output would be

<StudentData>
  <Corrected>
    <Student>
    <Name>Tom</Name>
    <Age>12</Age>
    <SSN>121-12-1234</SSN>
    </Student>
   <Student>....</Student>
  </Corrected>
  <Errored>
    <Student>
      <Name>Name cannot be blank</Name>
      <Age>13</Age>
      <SSN>123-12-1232</SSN>
    </Student>
 <Student>
      <Name>Name cannot be blank</Name>
      <Age>13</Age>
      <SSN>SSN should be none digit</SSN>
    </Student>

  </Errored>
</StudentData>


I am looking for XSLT to achieve this task.

THanks


 
Old July 20th, 2006, 01:28 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The simplest approach is to make two passes over your data. Do apply-templates mode="correct" to output the correct entries, then apply-templates mode="incorrect" to output the errors.

Of course that means testing each one twice. The alternative, which may be more efficient, is to output each one as it is first encountered, and then do a sort so that the correct ones appear first.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 20th, 2006, 07:06 PM
Authorized User
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pls provide me the xslt code.

 
Old July 20th, 2006, 11:31 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to explain where your problem lies: why can't you write the code yourself? I can help you if I know where your difficulties are. Doing the whole job for you achieves nothing.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





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