views:

38

answers:

2

I have the following XSLT code that almost does what I want:

<xsl:variable name="scoredItems"
              select=
                  ".//item/attributes/scored[@value='true'] |
                  self::section[attributes/variable_name/@value='SCORE']/item |
                  .//item//variables//variable_name"/>

I want to change this to a more complicated boolean expression:

<xsl:variable name="scoredItems"
              select=
                  ".//item/attributes/scored[@value='true'] or
                  (self::section[variable_name/@value='SCORE']/item and 
                   (not (.//item/attributes/scored[@value='false']))) or
                  .//item//variables//variable_name"/>

However, when I run this, I get the following error:

javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet     
at org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:832)     
at org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:618)

How do I fix this? (Note that I'm using XSLT 1.0.)

+1  A: 

In my experience, the default exception thrown by XSLT in Java is not very helpful. You'll need to implement an instance of ErrorListener and use its methods to capture and report the true XSLT problem. You can attach this ErrorListener using the setErrorListener method of your TransformerFactory.

Dan
A: 

I would greatly discourage anyone to write complicated expressions -- in any language!

This is not an XSLT question at all. It is a general programming question and the answer is:

Never write too complicated expressions because they are challenging to write, read, test, verify, proof, change.

Split a complicated expression onto a number of simpler expressions and assign them to different variables. Then operate on these variables.

Dimitre Novatchev