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 24th, 2008, 02:21 AM
Authorized User
 
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Match

HEllo friends,

I m novice to XSLT.
Please help me to find solution of My problem.

I have one XML file xfile1.
-<Xtag>
<ISA ISA01 =00 ISA02=02 />
<GS GS01 ="abc" GS02="def" />
</Xtag>

and My XSLT file IS

  <?xml version="1.0" encoding="us-ascii" ?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="/ISA |GS">
  <FileHeader ISA01Name="{@ISA01}" ISA02Name="{@ISA02}" GS01Name="{@GS01}" Gs02Name="{@GS02}" />
  </xsl:template>
  </xsl:stylesheet>

But It Gives Only value of GS node, But i want both in tag.

ie.
<fileheader ISA01Name=00 ISA02Name=02 GS01Name="abc" GS02Name="def" />


Thanks in advance.



 
Old July 24th, 2008, 02:57 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can use the <xsl:element> and <xsl:attribute> instructions to create elements and attributes in your output tree. You can also place xpath expressions inside a pair of braces to evaluation them, e.g. <FileHeader ISA01="{@ISA01}">... or <FileHeader><xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:@attribute>...

Give the above information try and work out a solution, and then if you are still stuck show us what you have got so far.

Also, you have not included quotes around your attribute values in the above example XML, which I assume is just laziness, but means that neither of the above bits of 'xml' are actually valid XML. Best to avoid this kind of laziness, especially when posting to a forum like this as it could be the difference between being given a right answer and a wrong one.

/- Sam Judson : Wrox Technical Editor -/
 
Old July 24th, 2008, 02:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What do have so far? (And that XML is not well-formed, start tag of document element is different to end tag.)

--

Joe (Microsoft MVP - XML)
 
Old July 24th, 2008, 03:22 AM
Authorized User
 
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for ur reply.

Would u please suggest me free-ebook to learn XSLT?






 
Old July 24th, 2008, 03:25 AM
Authorized User
 
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry i was in hurry.


Quote:
quote:Originally posted by joefawcett
 What do have so far? (And that XML is not well-formed, start tag of document element is different to end tag.)

--

Joe (Microsoft MVP - XML)
 
Old July 24th, 2008, 03:30 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Did you edit your original post? Please don't do that, as now my comment makes no sense...

Your template is being once when it matches the ISA element, then again when it matches the GS element. You need to match on the parent, and then pull the correct elements out of the child elements:

Code:
<xsl:template match="XTag">
  <FileHeader ISA01Name="{ISA/@ISA01}" ISA02Name="{ISA/@ISA02}"  GS01Name="{GS/@GS01}" Gs02Name="{GS/@GS02}" />
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/
 
Old July 24th, 2008, 03:33 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Also, regarding a book to learn XSLT - You do realise this is the WROX web site right?

You can however find tutorials on XSLT at http://www.w3schools.com/xsl/

/- Sam Judson : Wrox Technical Editor -/
 
Old July 24th, 2008, 03:39 AM
Authorized User
 
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Sam Judson,
Sorry for changing original content.
next time i will take care of it.
and
Thank you so much.
It works..



Quote:
quote:Originally posted by samjudson
 Did you edit your original post? Please don't do that, as now my comment makes no sense...

Your template is being once when it matches the ISA element, then again when it matches the GS element. You need to match on the parent, and then pull the correct elements out of the child elements:

Code:
<xsl:template match="XTag">
  <FileHeader ISA01Name="{ISA/@ISA01}" ISA02Name="{ISA/@ISA02}"  GS01Name="{GS/@GS01}" Gs02Name="{GS/@GS02}" />
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Match by attribute. ole_v2 XSLT 6 November 11th, 2006 10:24 AM
Match records bram_code VB Databases Basics 1 May 5th, 2006 10:36 AM
Help!! i need to get a closest match tseng Access VBA 3 February 4th, 2005 07:44 PM
match containing variable csbdeady XML 1 October 25th, 2004 05:57 AM





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