This discussion is archived
5 Replies Latest reply: May 23, 2012 7:52 AM by 805963 RSS

XSLT Transform in XML Signature: Exception

805963 Newbie
Currently Being Moderated
Hello,

I have following problem with an XSLT tranform in my XML signature. Here is the code I use to add XSLT to signature:

-----

main() {
...
DOMStructure stylesheet = new DOMStructure( getStylesheet() );
XSLTTransformParameterSpec spec = new XSLTTransformParameterSpec( stylesheet );

transforms.add( fac.newTransform( Transform.XSLT, spec ) );
...
}

private Element getStylesheet() throws Exception {
     String stylesheet = //"<?xml version=\"1.0\"?>" +
                    "<xslt:stylesheet version=\"1.0\" xmlns:xslt=\"http://www.w3.org/1999/XSL/Transform\">\n" +
                    " <xsl:include href=\"http://extern XSLT\" />\n" +
                    " <xslt:template match=\"/\">" +
                    " <xsl:apply-imports />" +
                    " </xslt:template>" +
                    "</xslt:stylesheet>\n";
          
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     
     //dbf.setValidating( true );
          
     return dbf.newDocumentBuilder().parse( new ByteArrayInputStream( stylesheet.getBytes() ) ).getDocumentElement();
}

-----

I get following exception:

-----

javax.xml.crypto.dsig.XMLSignatureException: javax.xml.crypto.dsig.TransformException: com.sun.org.apache.xml.internal.security.transforms.TransformationException: Cannot find xslt:stylesheet in Transform
Original Exception was com.sun.org.apache.xml.internal.security.transforms.TransformationException: Cannot find xslt:stylesheet in Transform
     at org.jcp.xml.dsig.internal.dom.DOMReference.transform(Unknown Source)
     at org.jcp.xml.dsig.internal.dom.DOMReference.digest(Unknown Source)
     at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.digestReference(Unknown Source)
     at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.sign(Unknown Source)

-----

In google I cannot find any details what can be wrong.

Any suggestions?

Thanks in advance,

errno
  • 1. Re: XSLT Transform in XML Signature: Exception
    gimbal2 Guru
    Currently Being Moderated
    Hm, I don't know much about XSLT directly but the content seems incorrect. You define an 'xslt' namespace, but I see you mix 'xsl' and 'xslt' namespaces.
  • 2. Re: XSLT Transform in XML Signature: Exception
    805963 Newbie
    Currently Being Moderated
    Thanks for your response. Sorry - I tried both versions with xslt and xsl - doesn't worked -> the error in my post is actually caused through the multiple changes of this part of code. Here once again:

    -----
    private Element getStylesheet() throws Exception {
              String stylesheet = //"<?xml version=\"1.0\"?>" +
                                       "<xslt:stylesheet version=\"1.0\" xmlns:xslt=\"http://www.w3.org/1999/XSL/Transform\">\n" +
                                       " <xslt:include href=\"external XSLTl\" />\n" +
                                       " <xslt:template match=\"/\">" +
                                       " <xslt:apply-imports />" +
                                       " </xslt:template>" +
                                       "</xslt:stylesheet>\n";
              
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              
              //dbf.setValidating( true );
              
              return dbf.newDocumentBuilder().parse( new ByteArrayInputStream( stylesheet.getBytes() ) ).getDocumentElement();
         }
    -----

    Thanks,
    errno
  • 3. Re: XSLT Transform in XML Signature: Exception
    EJP Guru
    Currently Being Moderated
    That gives the same exception?

    The prefix you use has to be declared somewhere. In your first version you had declared xsl but not xslt.
  • 4. Re: XSLT Transform in XML Signature: Exception
    805963 Newbie
    Currently Being Moderated
    yes - that gives the same exception :-(. and yes, as described before, different namespaces are caused through changes in code. neither xsl nor xslt namespace doesn't work.

    thanx
  • 5. Re: XSLT Transform in XML Signature: Exception
    805963 Newbie
    Currently Being Moderated
    does really nobody can help me with this problem? I'm still fighting with it...

    thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points