You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Suk Tae Kyung <tk...@penta.co.kr> on 2000/10/04 09:41:23 UTC

Q:How to pass parameter?

Hi, I'm using Xalan1.2. 

I want to sort XML output with param.(for dynamic transformation)

This  is test data.
/////////////////////////////////////////////////
<?xml version="1.0" ?>
<CUSTOMERS>
    <CUSTOMER>
     <NAME> B </NAME>
     <ADDRESS>  Addr1 </ADDRESS>
     <PHONE>  12345 </PHONE>
   </CUSTOMER>
   <CUSTOMER>
    <NAME> A </NAME>
    <ADDRESS> Addr2 </ADDRESS>
    <PHONE> 12345 </PHONE>
  </CUSTOMER>
  <CUSTOMER>
    <NAME> C </NAME>
    <ADDRESS> Addr3 </ADDRESS>
    <PHONE> 12345 </PHONE>
  </CUSTOMER>
</CUSTOMERS>
///////////////////////////////////////////////////


And this is  xsl .
/////////////////////////////////////////////////////////
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                version="1.0">
<xsl:output method="HTML"/>

<xsl:template match="CUSTOMERS">
<xsl:param name="temp" select="NAME"/>             <----- I set parameter here. I want to change parameter value dynamically later.    
 <HTML>
 <BODY>
 <TABLE>
 <xsl:for-each select="CUSTOMER">
 <xsl:sort select="($temp)" order="ascending"/>
 <TR>
     <TD><xsl:value-of select="NAME"/></TD>
     <TD><xsl:value-of select="ADDRESS"/> </TD>
     <TD><xsl:value-of select="PHONE"/> </TD>
 </TR>    
 </xsl:for-each> 
 </TABLE>
 </BODY>
        </HTML>
</xsl:template>
</xsl:stylesheet>

First, i tested XSL without parameter like this.
       java org.apache.xalan.xslt.Process -IN customer.xml -XSL customer.xsl -OUT newcust.html

But the output isn't what i intended.
What's wrong with my xsl? Thanks in advance.

Re: Q:How to pass parameter?

Posted by Everett Stauffer <ev...@chem.ucsd.edu>.
Like you, I expected the xsl:sort to match on a 'string'.
Obviously it doesn't.  xsl:sort expects to be matching on
a node(set).  Instead of using select="($temp)", try using
select="./*[name(.) = $temp]" ;  assuming you're looking to
sort the nodes by name, not by value.


Everett


> Suk Tae Kyung wrote:
> 
> Hi, I'm using Xalan1.2.
> 
> I want to sort XML output with param.(for dynamic transformation)
> 
> This  is test data.
> /////////////////////////////////////////////////
> <?xml version="1.0" ?>
> <CUSTOMERS>
>     <CUSTOMER>
>      <NAME> B </NAME>
>      <ADDRESS>  Addr1 </ADDRESS>
>      <PHONE>  12345 </PHONE>
>    </CUSTOMER>
>    <CUSTOMER>
>     <NAME> A </NAME>
>     <ADDRESS> Addr2 </ADDRESS>
>     <PHONE> 12345 </PHONE>
>   </CUSTOMER>
>   <CUSTOMER>
>     <NAME> C </NAME>
>     <ADDRESS> Addr3 </ADDRESS>
>     <PHONE> 12345 </PHONE>
>   </CUSTOMER>
> </CUSTOMERS>
> ///////////////////////////////////////////////////
> 
> 
> And this is xsl .
> /////////////////////////////////////////////////////////
> <?xml version="1.0" ?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 version="1.0">
> <xsl:output method="HTML"/>
> 
> <xsl:template match="CUSTOMERS">
> <xsl:param name="temp" select="NAME"/>             <----- I set parameter
> here. I want to change parameter value dynamically later.
>  <HTML>
>  <BODY>
>  <TABLE>
>  <xsl:for-each select="CUSTOMER">
>  <xsl:sort select="($temp)" order="ascending"/>
>  <TR>
>      <TD><xsl:value-of select="NAME"/></TD>
>      <TD><xsl:value-of select="ADDRESS"/> </TD>
>      <TD><xsl:value-of select="PHONE"/> </TD>
>  </TR>
>  </xsl:for-each>
>  </TABLE>
>  </BODY>
>         </HTML>
> </xsl:template>
> </xsl:stylesheet>
> 
> First, i tested XSL without parameter like this.
>        java org.apache.xalan.xslt.Process -IN customer.xml -XSL customer.xsl
> -OUT newcust.html
> 
> But the output isn't what i intended.
> What's wrong with my xsl? Thanks in advance.