 |
| 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
|
|
|
|

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

July 24th, 2008, 02:57 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

July 24th, 2008, 02:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

July 24th, 2008, 03:22 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for ur reply.
Would u please suggest me free-ebook to learn XSLT?
|
|

July 24th, 2008, 03:25 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)
|
|
|

July 24th, 2008, 03:30 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

July 24th, 2008, 03:33 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

July 24th, 2008, 03:39 AM
|
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 -/
|
|
|
 |