You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by ceclauson <ce...@hotmail.com> on 2008/07/15 08:37:31 UTC

Xalan doesn't seem to be doing transforms

Hello, I'm a bit new to XSLT and Xalan.

I'm trying to do an example transformation from a book I have on XSLT.  I've
tried it using both the command line tool and programmatically from a C++
program using the Xerces and Xalan libraries, and in both cases, the output
is simply the XSL file.

Here is the original XML file to transform, titled "people.xml":

<?xml version="1.0"?>

<people>
 <person born="1912" died="1954">
  <name>
   <first_name>Alan</first_name>
   <last_name>Turing</last_name>
  </name>
  <profession>computer scientist</profession>
  <profession>mathematician</profession>
  <profession>cryptographer</profession>
 </person>
 <person born="1918" died="1988">
  <name>
   <first_name>Richard</first_name>
   <middle_initial>P</middle_initial>
   <last_name>Feynman</last_name>
  </name>
  <profession>physicist</profession>
  <hobby>playing the bongos</hobby>
 </person>
</people>


Now here is the transform rule, titled "minimal.xsl":

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3c.org/1999/XSL/Transform">

	<xsl:template match="person">A person</xsl:template>

</xsl:stylesheet>


If I try to apply the transform to the original document with the following
command:

>xalan -in people.xml -xsl minimal.xsl -out out.txt

out.txt just contains the following:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet
xmlns:xsl="http://www.w3c.org/1999/XSL/Transform"
version="1.0"><xsl:template match="person">A
person</xsl:template></xsl:stylesheet>

Which is just the original xsl document, minus the whitespace between tags.

I've tried doing this same task programmatically and get the same results. 
Also, I've tried this with a different stylesheet, and again, the general
pattern is that the output is simply the stylesheet, minus whitespace.

By the way, the book tells me that what I should expect as output is simply
the input with the tags stripped away, and the "person" tag replaced with
the text "A person".

I figure there's probably something I'm missing.  Any help anyone could give
me would be very much appreciated.

Thanks,
Cooper
-- 
View this message in context: http://www.nabble.com/Xalan-doesn%27t-seem-to-be-doing-transforms-tp18458604p18458604.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.


Re: Xalan doesn't seem to be doing transforms

Posted by David Bertoni <db...@apache.org>.
ceclauson wrote:
> Hello, I'm a bit new to XSLT and Xalan.
> 
> I'm trying to do an example transformation from a book I have on XSLT.  I've
> tried it using both the command line tool and programmatically from a C++
> program using the Xerces and Xalan libraries, and in both cases, the output
> is simply the XSL file.
> 
> Here is the original XML file to transform, titled "people.xml":
> 
> <?xml version="1.0"?>
> 
> <people>
>  <person born="1912" died="1954">
>   <name>
>    <first_name>Alan</first_name>
>    <last_name>Turing</last_name>
>   </name>
>   <profession>computer scientist</profession>
>   <profession>mathematician</profession>
>   <profession>cryptographer</profession>
>  </person>
>  <person born="1918" died="1988">
>   <name>
>    <first_name>Richard</first_name>
>    <middle_initial>P</middle_initial>
>    <last_name>Feynman</last_name>
>   </name>
>   <profession>physicist</profession>
>   <hobby>playing the bongos</hobby>
>  </person>
> </people>
> 
> 
> Now here is the transform rule, titled "minimal.xsl":
> 
> <?xml version="1.0"?>
> 
> <xsl:stylesheet version="1.0"
> 		xmlns:xsl="http://www.w3c.org/1999/XSL/Transform">
> 
> 	<xsl:template match="person">A person</xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> If I try to apply the transform to the original document with the following
> command:
> 
>> xalan -in people.xml -xsl minimal.xsl -out out.txt
> 
> out.txt just contains the following:
> 
> <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet
> xmlns:xsl="http://www.w3c.org/1999/XSL/Transform"
> version="1.0"><xsl:template match="person">A
> person</xsl:template></xsl:stylesheet>
> 
> Which is just the original xsl document, minus the whitespace between tags.
> 
> I've tried doing this same task programmatically and get the same results. 
> Also, I've tried this with a different stylesheet, and again, the general
> pattern is that the output is simply the stylesheet, minus whitespace.
You've specified the XSLT namespace incorrectly.  It's:

"http://www.w3.org/1999/XSL/Transform"

> 
> By the way, the book tells me that what I should expect as output is simply
> the input with the tags stripped away, and the "person" tag replaced with
> the text "A person".
Either the book is wrong, or you're not reading it correctly.  The 
default rules copy text nodes and attribute values to the result tree, 
so those will be invoked for the root element and any of its children.

Since you have a template that matches the "person" element nodes, a 
text node with the value "A person" will be copied to the result tree 
for each of them.  However, the children of the "person" element nodes 
will not be matched, so none of their descendants are processed.

I would suggest you fix the namespace URI in the stylesheet, and try it 
with the following document:

<?xml version="1.0"?>
<people>textnode1<person born="1912" died="1954">
   <name>
    <first_name>Alan</first_name>
    <last_name>Turing</last_name>
   </name>
   <profession>computer scientist</profession>
   <profession>mathematician</profession>
   <profession>cryptographer</profession>
  </person>textnode2<person born="1918" died="1988">
   <name>
    <first_name>Richard</first_name>
    <middle_initial>P</middle_initial>
    <last_name>Feynman</last_name>
   </name>
   <profession>physicist</profession>
   <hobby>playing the bongos</hobby>
  </person>textnode3</people>

I've replaced the whitespace text node children of the "people" element 
with "numbered" text nodes, which should give you a clearer idea of what 
the processor is doing.

For general XSLT questions, I suggest you subscribe to the Mulberry 
Technologies XSL list.  It's a great resource and there are many very 
knowledgeable people who can answer your questions.

Dave