|
Subject:
|
XSLT Match
|
|
Posted By:
|
Mitali
|
Post Date:
|
7/24/2008 2:21:37 AM
|
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.
|
|
Reply By:
|
samjudson
|
Reply Date:
|
7/24/2008 2:57:18 AM
|
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 -/
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
7/24/2008 2:57:28 AM
|
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)
|
|
Reply By:
|
Mitali
|
Reply Date:
|
7/24/2008 3:22:44 AM
|
Thanks for ur reply.
Would u please suggest me free-ebook to learn XSLT?
|
|
Reply By:
|
Mitali
|
Reply Date:
|
7/24/2008 3:25:35 AM
|
sorry i was in hurry.
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)
|
|
Reply By:
|
samjudson
|
Reply Date:
|
7/24/2008 3:30:19 AM
|
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:
<xsl:template match="XTag">
<FileHeader ISA01Name="{ISA/@ISA01}" ISA02Name="{ISA/@ISA02}" GS01Name="{GS/@GS01}" Gs02Name="{GS/@GS02}" />
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/
|
|
Reply By:
|
samjudson
|
Reply Date:
|
7/24/2008 3:33:43 AM
|
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 -/
|
|
Reply By:
|
Mitali
|
Reply Date:
|
7/24/2008 3:39:12 AM
|
Hey Sam Judson, Sorry for changing original content. next time i will take care of it. and Thank you so much. It works..
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:
<xsl:template match="XTag">
<FileHeader ISA01Name="{ISA/@ISA01}" ISA02Name="{ISA/@ISA02}" GS01Name="{GS/@GS01}" Gs02Name="{GS/@GS02}" />
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/
|