You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Matthew Langham <ml...@sundn.de> on 2000/03/29 15:21:31 UTC

XSL-Help

Hi!

We are beginners when it comes to XSL - and would like to do the following:

We have an XML stream which looks like this:

<XML>
	<MAPPINGS>
		<ACCOUNT>
			<TYPE>15</TYPE>
			<DESCRIPTION>This is short</DESCRIPTION>
		</ACCOUNT>
		<ACCOUNT>
			<TYPE>16</TYPE>
			<DESCRIPTION>Shorter</DESCRIPTION>
		</ACCOUNT>
	</MAPPINGS>
 	<ACCOUNTLIST>
		<ACCOUNT>
			<NUMBER>123456789<NUMBER>
			<TYPE>15</TYPE>
			<DESCRIPTION>This is a long description</DESCRIPTION>
		</ACCOUNT>
		<ACCOUNT>
			<NUMBER>11111111<NUMBER>
			<TYPE>16</TYPE>
			<DESCRIPTION>This is a longer description</DESCRIPTION>
		</ACCOUNT>
	</ACCOUNTLIST>
	<MAPPINGS>
</XML>

In the output each ACCOUNT in ACCOUNTLIST should have its DESCRIPTION
replaced with a DESCRIPTION from the corresponding ACCOUNT in the MAPPINGS
section (depending on the type). i.e. replace the long description with the
short one.

How can this be achieved using XSL and cocoon?

Thanks

Matthew

--
=================================================================
Matthew Langham, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
Tel: +49-5251-1581-30   [mlangham@sundn.de - http://www.sundn.de]
=================================================================


------------------------------------------------------------------------------------------
...this mail was scanned for viruses by mailserver...

RE: XSL-Help

Posted by Erik Norvelle <er...@norvelle.net>.
Matthew:

At the very top of your .xml file, put the following XML processing
instructions:

<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="put-your-xsl-file-here.xsl" type="text/xsl"?>

The xslt process line will tell Cocoon to run the XML output of your file
through Xalan (the XSL processor), and the stylesheet line tells Cocoon
which xsl file to apply.

A tutorial on XSLT is beyond the scope of this post, but I do have a couple
of helpful online references for you:

A good tutorial: http://nwalsh.com/docs/tutorials/xsl/xsl/frames.html
A book you can purchase/download online:
http://www.cranesoftwrights.com/training/index.htm

Hope this helps...

-Erik

--------------------------------------------+
Erik Norvelle                               |
Support Systems Analyst, Sr.                |
The University of Arizona                   |
College of Agriculture                      |
Educational Communications and Technologies |
email:  norvelle@ag.arizona.edu             |
phone:  520-621-7663                        |
fax:    520-621-9889                        |
--------------------------------------------+
Credo in unum Deum                          |
--------------------------------------------+

> -----Original Message-----
> From: Matthew Langham [mailto:mlangham@sundn.de]
> Sent: Wednesday, March 29, 2000 6:22 AM
> To: cocoon-users@xml.apache.org
> Subject: XSL-Help
>
>
> Hi!
>
> We are beginners when it comes to XSL - and would like to do the
> following:
>
> We have an XML stream which looks like this:
>
> <XML>
> 	<MAPPINGS>
> 		<ACCOUNT>
> 			<TYPE>15</TYPE>
> 			<DESCRIPTION>This is short</DESCRIPTION>
> 		</ACCOUNT>
> 		<ACCOUNT>
> 			<TYPE>16</TYPE>
> 			<DESCRIPTION>Shorter</DESCRIPTION>
> 		</ACCOUNT>
> 	</MAPPINGS>
>  	<ACCOUNTLIST>
> 		<ACCOUNT>
> 			<NUMBER>123456789<NUMBER>
> 			<TYPE>15</TYPE>
> 			<DESCRIPTION>This is a long
> description</DESCRIPTION>
> 		</ACCOUNT>
> 		<ACCOUNT>
> 			<NUMBER>11111111<NUMBER>
> 			<TYPE>16</TYPE>
> 			<DESCRIPTION>This is a longer
> description</DESCRIPTION>
> 		</ACCOUNT>
> 	</ACCOUNTLIST>
> 	<MAPPINGS>
> </XML>
>
> In the output each ACCOUNT in ACCOUNTLIST should have its DESCRIPTION
> replaced with a DESCRIPTION from the corresponding ACCOUNT in the MAPPINGS
> section (depending on the type). i.e. replace the long
> description with the
> short one.
>
> How can this be achieved using XSL and cocoon?
>
> Thanks
>
> Matthew
>
> --
> =================================================================
> Matthew Langham, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
> Tel: +49-5251-1581-30   [mlangham@sundn.de - http://www.sundn.de]
> =================================================================
>
>
> ------------------------------------------------------------------
> ------------------------
> ...this mail was scanned for viruses by mailserver...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>

Re: XSL-Help

Posted by Antonio Menchero =?iso-8859-1?Q?Fern�ndez?= <am...@aqs.es>.
In the template for elements /XML/ACCOUNTLIST/ACCOUNT you could write the 
following:

<xsl:template match="ACCOUNT">
         ....
         ...
         <xsl:variable name="localtype" select="TYPE"/>
         <DESCRIPTION><xsl:value-of 
select="/XML/MAPPINGS/ACCOUNT[TYPE=$localtype]/DESCRIPTION" /></DESCRIPTION>
         ...
</xsl:template>


Luck!


At 15.21 29/3/00 +0200, you wrote:
>Hi!
>
>We are beginners when it comes to XSL - and would like to do the following:
>
>We have an XML stream which looks like this:
>
><XML>
>         <MAPPINGS>
>                 <ACCOUNT>
>                         <TYPE>15</TYPE>
>                         <DESCRIPTION>This is short</DESCRIPTION>
>                 </ACCOUNT>
>                 <ACCOUNT>
>                         <TYPE>16</TYPE>
>                         <DESCRIPTION>Shorter</DESCRIPTION>
>                 </ACCOUNT>
>         </MAPPINGS>
>         <ACCOUNTLIST>
>                 <ACCOUNT>
>                         <NUMBER>123456789<NUMBER>
>                         <TYPE>15</TYPE>
>                         <DESCRIPTION>This is a long description</DESCRIPTION>
>                 </ACCOUNT>
>                 <ACCOUNT>
>                         <NUMBER>11111111<NUMBER>
>                         <TYPE>16</TYPE>
>                         <DESCRIPTION>This is a longer 
> description</DESCRIPTION>
>                 </ACCOUNT>
>         </ACCOUNTLIST>
>         <MAPPINGS>
></XML>
>
>In the output each ACCOUNT in ACCOUNTLIST should have its DESCRIPTION
>replaced with a DESCRIPTION from the corresponding ACCOUNT in the MAPPINGS
>section (depending on the type). i.e. replace the long description with the
>short one.
>
>How can this be achieved using XSL and cocoon?
>
>Thanks
>
>Matthew
>
>--
>=================================================================
>Matthew Langham, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
>Tel: +49-5251-1581-30   [mlangham@sundn.de - http://www.sundn.de]
>=================================================================
>
>
>------------------------------------------------------------------------------------------
>...this mail was scanned for viruses by mailserver...
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org