[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Design question

Subject: RE: Design question
From: "XSLList" <xsllist@xxxxxxxxxxxxx>
Date: Sun, 9 Feb 2003 20:53:04 -0500
RE:  Design question
Wanted:
>BEFORE:
>     <test type="positive" name="Test 1">
>         <param name="p1">123</param>
>         <param name="date1">July 9</param>
>         <param name="p2">false</param>
>     </test>
>
>AFTER:
>     <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
robust.

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



<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:output method="xml" indent="yes"/>

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

<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:element>
</xsl:template>

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

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

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



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


Current Thread
  • RE: Design question
    • XSLList - Sun, 9 Feb 2003 20:49:55 -0500 (EST) <=
      • <Possible follow-ups>
      • XSLList - Sun, 9 Feb 2003 20:54:52 -0500 (EST)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.