You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Bradley Wagner <br...@hannonhill.com> on 2008/10/02 23:36:15 UTC

Validating XSLT by building a Templates or Transformer object

Hi, we're currently validating XSLTs submitted by our users by using  
the org.apache.xalan.processor.TransformerFactoryImpl to create new  
Templates objects with TransformerFactory.newTemplates(Source). The  
problem is that when we actually apply these XSLT stylesheets we pass  
transformer parameters that our XSLT writers can use.

We're running into problems because we can't figure out how to  
validate the XSLTs while passing these parameters in. I keep getting  
errors saying that the validation failed because: Could not find  
variable with the name of system-interface (the name of one of our  
parameters).

Any ideas?

Thanks,
Bradley

Re: Validating XSLT by building a Templates or Transformer obje

Posted by Bradley Wagner <br...@hannonhill.com>.
Yeah, I found that too. Thanks Timothy. Apparently you can specify the  
presence of a param without a default value as well:

<xsl:param name="inApp"/>

- Bradley

On Oct 3, 2008, at 7:40 PM, Timothy Jones wrote:

> Hi Bradley...
>
> I was under the impression that you had to pass them along with each  
> template, starting with the <xsl:template match='/'> tag, and pass  
> them to the other templates that need them like this:
>
>    <xsl:apply-templates select='node-spec'>
>       <xsl:with-param name='key' select='value' />
>             <!-- note the "with-".  This is different tag than the  
> <xsl:param> that you use in an <xsl:template>. -->
>    </xsl:apply-templates>
>
> in a similar fashion to how you might add an argument to a bunch of  
> methods in order to get them to the methods that need them.
>
> But when I looked up the spec earlier (hoping to help), I noticed  
> that you can place a <xsl:param> tag in a global context at the top  
> of the stylesheet (outside of any <xsl:template> tag.  Look at  
> Listing 2 in http://www.ibm.com/developerworks/xml/library/x-tipxsltrun/index.html 
>  for an example.
>
> Fortunately, each param has a name, which means the physical order  
> of the param tags doesn't matter.  Nice!
>
> Now I realize that my initial statement in this post about where you  
> have to put param tags is probably excessive.   I just wanted to  
> pipe up and let you know about the global declaration method, while  
> I go back and see what is actually necessary.  (I'm no big expert, I  
> just have used XSL in a few server-side Java apps over the years).
>
>
>
> tlj
>
> Timothy  Jones
> personal email: tim@timjones.com
> From: Bradley Wagner [mailto:bradley.wagner@hannonhill.com]
> Sent: Friday, October 03, 2008 6:57 PM
> To: keshlam@us.ibm.com
> Cc: xalan-j-users@xml.apache.org
> Subject: Re: Validating XSLT by building a Templates or Transformer  
> obje
>
> Was looking online for where to do this exactly. Is it just:
>
> <xsl:param name="inApp">no</xsl:param>
>
> where I declare the parameter with a default value? Is there a way  
> to just declare that a parameter will exist (will be supplied) but  
> is not set?
>
> On Oct 2, 2008, at 7:48 PM, keshlam@us.ibm.com wrote:
>
>>
>> You haven't declared your stylesheet parameter in the XSLT. Fix  
>> that and see where it gets you.
>>
>> ______________________________________
>> "... Three things see no end: A loop with exit code done wrong,
>> A semaphore untested, And the change that comes along. ..."
>>  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html 
>> )
>


RE: Validating XSLT by building a Templates or Transformer obje

Posted by Timothy Jones <Ti...@syniverse.com>.
Hi Bradley... 
 
I was under the impression that you had to pass them along with each
template, starting with the <xsl:template match='/'> tag, and pass them
to the other templates that need them like this:
 
   <xsl:apply-templates select='node-spec'>
      <xsl:with-param name='key' select='value' />
            <!-- note the "with-".  This is different tag than the
<xsl:param> that you use in an <xsl:template>. -->
   </xsl:apply-templates>
 
in a similar fashion to how you might add an argument to a bunch of
methods in order to get them to the methods that need them.
 
But when I looked up the spec earlier (hoping to help), I noticed that
you can place a <xsl:param> tag in a global context at the top of the
stylesheet (outside of any <xsl:template> tag.  Look at Listing 2 in
http://www.ibm.com/developerworks/xml/library/x-tipxsltrun/index.html
for an example.
 
Fortunately, each param has a name, which means the physical order of
the param tags doesn't matter.  Nice!
 
Now I realize that my initial statement in this post about where you
have to put param tags is probably excessive.   I just wanted to pipe up
and let you know about the global declaration method, while I go back
and see what is actually necessary.  (I'm no big expert, I just have
used XSL in a few server-side Java apps over the years).
 
 
 
tlj
 
Timothy  Jones
personal email: tim@timjones.com <ma...@timjones.com> 
________________________________

From: Bradley Wagner [mailto:bradley.wagner@hannonhill.com] 
Sent: Friday, October 03, 2008 6:57 PM
To: keshlam@us.ibm.com
Cc: xalan-j-users@xml.apache.org
Subject: Re: Validating XSLT by building a Templates or Transformer obje


Was looking online for where to do this exactly. Is it just: 

<xsl:param name="inApp">no</xsl:param>

where I declare the parameter with a default value? Is there a way to
just declare that a parameter will exist (will be supplied) but is not
set?

On Oct 2, 2008, at 7:48 PM, keshlam@us.ibm.com wrote:



	You haven't declared your stylesheet parameter in the XSLT. Fix
that and see where it gets you. 
	
	______________________________________
	"... Three things see no end: A loop with exit code done wrong,
	A semaphore untested, And the change that comes along. ..."
	 -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html
<http://www.ovff.org/pegasus/songs/threes-rev-11.html> )



Re: Validating XSLT by building a Templates or Transformer obje

Posted by Bradley Wagner <br...@hannonhill.com>.
Was looking online for where to do this exactly. Is it just:

<xsl:param name="inApp">no</xsl:param>

where I declare the parameter with a default value? Is there a way to  
just declare that a parameter will exist (will be supplied) but is not  
set?

On Oct 2, 2008, at 7:48 PM, keshlam@us.ibm.com wrote:

>
> You haven't declared your stylesheet parameter in the XSLT. Fix that  
> and see where it gets you.
>
> ______________________________________
> "... Three things see no end: A loop with exit code done wrong,
> A semaphore untested, And the change that comes along. ..."
>  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html 
> )


Re: Validating XSLT by building a Templates or Transformer obje

Posted by ke...@us.ibm.com.
You haven't declared your stylesheet parameter in the XSLT. Fix that and 
see where it gets you.

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (
http://www.ovff.org/pegasus/songs/threes-rev-11.html)

Re: Validating XSLT by building a Templates or Transformer objec

Posted by Bradley Wagner <br...@hannonhill.com>.
Ah, good point. Here you go:

Examples XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:java="http://xml.apache.org/xslt/java 
" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:template match="begin">
     <xsl:if test="$system-interface = 'publish'">
         <publish>publish content</publish>
     </xsl:if>
     <xsl:if test="$system-interface = 'admin'">
         <cms>in cms</cms>
     </xsl:if>
</xsl:template>
</xsl:stylesheet>
The Java code we're using to validate:
String xslt;
TransformerFactory transformerFactory = new  
org.apache.xalan.processor.TransformerFactoryImpl();
transformerFactory.newTemplates(new SAXSource(new InputSource(new  
BufferedReader(new StringReader(xslt)))));
The string "xslt" is their stylesheet like the example above. "system- 
interface" is the name of the parameter we're passing to the  
transformer for their use.
Thanks!
On Oct 2, 2008, at 6:07 PM, keshlam@us.ibm.com wrote:

>
> Guess: Sounds like the problem is in how you're asserting those  
> parameters and/or how you've declared them in the stylesheet.
>
> Hard to say anything more useful without seeing that code.
>
> ______________________________________
> "... Three things see no end: A loop with exit code done wrong,
> A semaphore untested, And the change that comes along. ..."
>  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html 
> )
>
>
> Bradley Wagner <br...@hannonhill.com>
> 10/02/2008 05:36 PM
>
> To
> xalan-j-users@xml.apache.org
> cc
> Subject
> Validating XSLT by building a Templates or Transformer object
>
>
>
>
>
> Hi, we're currently validating XSLTs submitted by our users by using  
> the org.apache.xalan.processor.TransformerFactoryImpl to create new  
> Templates objects with TransformerFactory.newTemplates(Source). The  
> problem is that when we actually apply these XSLT stylesheets we  
> pass transformer parameters that our XSLT writers can use.
>
> We're running into problems because we can't figure out how to  
> validate the XSLTs while passing these parameters in. I keep getting  
> errors saying that the validation failed because: Could not find  
> variable with the name of system-interface (the name of one of our  
> parameters).
>
> Any ideas?
>
> Thanks,
> Bradley