RE: [xsl] Design question

Subject: RE: [xsl] Design question
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Tue, 11 Feb 2003 14:12:21 -0600
It may have been 7 mos. old, but it was helpful for me to
see the question and your answer.  I'm even more of a beginner
than you so it was a good exercise for me too.

However, a couple of things are missing from your solution...
(1) the da: namespace prefix, and
(2) capitalizing 'Positive' element name.

Below is my solution (based on yours).

However when I tried to add "da:" to the output elements,
xsl gave me an unknown namespace error unless I added
a namespace declaration to the <xsl:stylesheet> element.  Whereupon
the output da:Positive element also took on a xmlns:da="..." declaration.
I assume that's by design though I haven't thought through
why it ought to be so.

Anyway, I welcome anyone's comments on how to do this better.


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

>  Input:
> >     <test type="positive" name="Test 1">
> >         <param name="p1">123</param>
> >         <param name="date1">July 9</param>
> >         <param name="p2">false</param>
> >     </test>
>  Desired output:
>     <da:Positive name="Test 1" p1="123" p2="false">
>        <da:Date number="1" value="July 9"/>
>     </da:Positive>

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

<xsl:template match="test">
  <xsl:element name="{concat('da:', translate(substring(@type, 1, 1),
'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
substring(@type, 2))}">
    <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="da: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