RE: [xsl] Newby Question reformatting xml

Subject: RE: [xsl] Newby Question reformatting xml
From: "Yates, Danny (ANTS)" <danny.yates@xxxxxxxxxx>
Date: Mon, 17 Feb 2003 14:31:21 -0000
Hi Michael,

Very close!

Replace

  <xsl:value-of select="//DDD/@id"></xsl:value-of>

with

  <xsl:value-of select="../@id"/>

Also, your indenting suggests that you think your CCC nodes are
children of your BBB nodes. They're not.

Also, you are making gratuitous use of <xsl:element> and
<xsl:attribute>! Try this, it's much clearer:

  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  
    <xsl:output method="xml" indent="yes"/>
  
    <xsl:template match="AAA">
      <AAA>
        <xsl:apply-templates select="DDD"/>
      </AAA>
    </xsl:template>
  
    <xsl:template match="DDD">
      <DDD>
        <xsl:apply-templates select="BBB"/>
      </DDD>
    </xsl:template>
  
    <xsl:template match="BBB">
      <BBB num="{../@id}">
        <xsl:value-of select="."/>
      </BBB>
    </xsl:template>
  </xsl:stylesheet>

Rgds,

Dan.



-----Original Message-----
From: Michael A. Thompson [mailto:mathomp@xxxxxxxxxxxxxx]
Sent: 17 February 2003 13:44
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Newby Question reformatting xml


I am new to XSL and trying to get a grasp of the language. I need to 
totally reformat some xml files and have a question about node paths.

Example XML file:

<?xml version="1.0" encoding="UTF-8"?>
<AAA>
	<DDD id="test1">
		<BBB>10</BBB>
			<CCC>ccc</CCC>
		<BBB>5</BBB>
		<BBB>7</BBB>
	</DDD>
	<DDD id="test2">
		<BBB>1</BBB>
		<BBB>2</BBB>
			<CCC>ccc</CCC>
		<BBB>3</BBB>
	</DDD>
</AAA>

What I want to new XML file to look like:

<?xml version="1.0" encoding="UTF-8"?>
<AAA>
	<DDD>
		<BBB num="test1">10</BBB>
		<BBB num="test1">5</BBB>
		<BBB num="test1">7</BBB>
	</DDD>
	<DDD>
		<BBB num="test2">1</BBB>
		<BBB num="test2">2</BBB>
		<BBB num="test2">3</BBB>
	</DDD>
</AAA>

My XSL file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">

	<xsl:output method="xml" indent="yes"/>
	
	<xsl:template match="AAA">
		<xsl:element name="AAA">
			<xsl:apply-templates select="DDD" />
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="DDD">
		<xsl:element name="DDD">
			<xsl:apply-templates
select="BBB"></xsl:apply-templates>
		</xsl:element>
		
	</xsl:template>
	
	<xsl:template match="BBB">
		<xsl:element name="BBB">
			<xsl:attribute name="num">
				<xsl:value-of
select="//DDD/@id"></xsl:value-of>
			</xsl:attribute>
			<xsl:value-of select="."></xsl:value-of>
		</xsl:element>
	</xsl:template>
	
</xsl:stylesheet>

Thanks,
Michael


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


***************************************************************************
This communication (including any attachments) contains confidential information.  If you are not the intended recipient and you have received this communication in error, you should destroy it without copying, disclosing or otherwise using its contents.  Please notify the sender immediately of the error.

Internet communications are not necessarily secure and may be intercepted or changed after they are sent.  Abbey National Treasury Services plc does not accept liability for any loss you may suffer as a result of interception or any liability for such changes.  If you wish to confirm the origin or content of this communication, please contact the sender by using an alternative means of communication.

This communication does not create or modify any contract and, unless otherwise stated, is not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 2 Triton Square, Regents Place, London NW1 3AN.  Registered in England under Company Registration Number: 2338548.  Regulated by the Financial Services Authority (FSA).
***************************************************************************


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread