RE: [xsl] Design question

Subject: RE: [xsl] Design question
From: "XSLList" <xsllist@xxxxxxxxxxxxx>
Date: Sun, 9 Feb 2003 20:53:04 -0500
>     <test type="positive" name="Test 1">
>         <param name="p1">123</param>
>         <param name="date1">July 9</param>
>         <param name="p2">false</param>
>     </test>
>     <da:Positive name="Test 1" p1="123" p2="false">
>        <da:Date number="1" value="July 9"/>
>     </da:Positive>

I tested this and it works.  As I see it, the weakness in my approach is
that I'm making assumptions in how your param elements may vary.  (I.e. I
hard-coded 'date' in one template, and make the assumption that the names
won't vary.)  It was tested using MSXML 4.  It seems to me that you could
easily build templates for each name pattern and extend this to be more

I'm just learning, so these little exercises are helpful!  --Jeff

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl='' >
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
	<xsl:apply-templates select="test"/>

<xsl:template match="test">
	<xsl:element name="{@type}">
		<xsl:copy-of select="@name"/>
		<xsl:apply-templates select="param[contains(@name,'p')]"/>
		<xsl:apply-templates select="param[contains(@name,'date')]"/>

<xsl:template match="param[contains(@name,'p')]">
	<xsl:attribute name="{@name}">
		<xsl:value-of select="."/>

<xsl:template match="param[contains(@name,'date')]">
		<xsl:element name="Date">
			<xsl:attribute name="number">
				<xsl:value-of select="translate(@name,

			<xsl:attribute name="value">
				<xsl:value-of select="."/>

 XSL-List info and archive:

Current Thread