Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2010, 10:14 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

Java code that works without calling the saxon:parse function


Code:
String mystring = System.setProperty("javax.xml.transform.TransformerFactory", "com.saxonica.config.ProfessionalTransformerFactory");  


   // Create a transform factory instance.  
       TransformerFactory tfactory1 = TransformerFactory.newInstance();  
  
      File xsl1 = new File("E:\\apache-tomcat-6.0.20\\webapps\\orbeon\\xforms-jsp\\Andy\\pdfs\\temp.xsl");

     Source xsltSrc1 = new StreamSource(xsl1);
    
    Transformer transformer1 = tfactory1.newTransformer(xsltSrc1);
  
  File file1 = new File("E:\\apache-tomcat-6.0.20\\webapps\\orbeon\\xforms-jsp\\Andy\\pdfs\\temp.fo");

  FileOutputStream myFileOutputStream1 = new FileOutputStream(file1);
  
 Source src1 = new StreamSource("E:\\apache-tomcat-6.0.20\\webapps\\orbeon\\xforms-jsp\\Andy\\pdfs\\temp.xml");
 
 StreamResult res1 = new  StreamResult(myFileOutputStream1);
 
  transformer1.transform(src1,res1) ;
The xsl code below, note it calls saxon:parse at the bottom of the file.


Code:
<?xml version="1.0"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:fox="http://xml.apache.org/fop/extensions" xmlns:xalan="http://xml.apache.org/xalan"
    exclude-result-prefixes="xalan" xmlns:exsl="http://exslt.org/common" xmlns:saxon="saxon.sf.net"
    extension-element-prefixes="exsl saxon">
    <!--
    <xsl:value-of select="system-property('xsl:vendor')"/> 
    -->
    
    <xsl:variable name="rootstart" select="concat('&lt;root','&gt;')"></xsl:variable>
    <xsl:variable name="rootend" select="concat('&lt;/root','&gt;')"></xsl:variable>
    <xsl:template match="/">
        
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="temp"
                    margin-top="25pt" margin-bottom="25pt"
                    page-width="11in" page-height="8.5in"
                    margin-left="25pt" margin-right="25pt">
                    <fo:region-body margin-bottom="50pt" margin-top="100pt"/>
                    <fo:region-before extent="100pt" />
                    <fo:region-after extent="25pt" />
                </fo:simple-page-master>
            </fo:layout-master-set>
            
            <fo:page-sequence master-reference="temp">
                
                <fo:static-content flow-name="xsl-region-before">
                    <fo:block font-size="18pt" color="navy">
                        <fo:inline></fo:inline>
                    </fo:block>
                </fo:static-content>
                
                <fo:static-content flow-name="xsl-region-after">
                    <fo:block text-align="left" font-size="8pt">
                        <fo:inline padding-left="75%">
                            Page <fo:page-number />
                        </fo:inline>
                    </fo:block>
                </fo:static-content>
                
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                        <xsl:choose>
                            <xsl:when test="data/formtype = 'Product Liability/Completed Operations Coverage'">
                                <fo:block font-weight="bold">
                                   <fo:block line-height="15mm" font-size="22pt"><xsl:value-of select="data/formtype"/></fo:block>
                                   <fo:table>
                                       <fo:table-column column-width="20mm"/>
                                       <fo:table-column column-width="10mm"/>
                                       <fo:table-column column-width="120mm"/>
                                       <fo:table-column column-width="30mm"/>
                                       <fo:table-column column-width="30mm"/>
                                       <fo:table-column column-width="30mm"/>
                                       <fo:table-body>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block font-size="18pt">I.</fo:block></fo:table-cell>
                                               <fo:table-cell number-columns-spanned="2" font-size="18pt"><fo:block>Description</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>Acceptable </fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>Comments/Recs</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>N/A</fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>a.</fo:block></fo:table-cell>
                                               <fo:table-cell ><fo:block>Who Are Products Sold To?</fo:block></fo:table-cell>
                                               <fo:table-cell number-columns-spanned="3"><fo:block ><xsl:value-of select="data/description/who"/></fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>b.</fo:block></fo:table-cell>
                                               <fo:table-cell ><fo:block>Describe the Product(s):</fo:block></fo:table-cell>
                                               <fo:table-cell number-columns-spanned="3"><fo:block ><xsl:value-of select="data/description/decribe"/></fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>c.</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>Any Private Labelling?</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/private = 1">Yes</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/private = 0">No</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/private = 2">N/A</xsl:if></fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>d.</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>Does Ins'd Manufacture the Product?</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/manufacture = 1">Yes</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/manufacture = 0">No</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/manufacture = 2">N/A</xsl:if></fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>e.</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>Are there Any Aircraft or Military Applications?</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/aircraft = 1">Yes</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/aircraft = 0">No</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/aircraft = 2">N/A</xsl:if></fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>f.</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block>Any Vehicle Steering or Brake Parts?</fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/brake = 1">Yes</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/brake = 0">No</xsl:if></fo:block></fo:table-cell>
                                               <fo:table-cell><fo:block><xsl:if test="data/description/brake = 2">N/A</xsl:if></fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell number-columns-spanned="5"><fo:block>Comments:</fo:block></fo:table-cell>
                                           </fo:table-row>
                                           <fo:table-row>
                                               <fo:table-cell><fo:block></fo:block></fo:table-cell>
                                               <fo:table-cell number-columns-spanned="5">
                                                   <fo:block>
                                                <xsl:apply-templates select="saxon:parse(concat($rootstart,data/description/comments,$rootend))"></xsl:apply-templates>
                                                       <xsl:value-of select="system-property('xsl:vendor')"/>
                                                       
                                                   </fo:block>
                                               </fo:table-cell>
                                           </fo:table-row>
                                       </fo:table-body>
                                   </fo:table>
                                </fo:block>
                                
                                
                                
                                
                            </xsl:when>
                        </xsl:choose>
                        
                        
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
   <xsl:template match="br">
       <fo:block line-height="10mm"></fo:block>
   </xsl:template>
    <xsl:template match="text()">
        <xsl:copy></xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Now I am running xforms on the front end and this sends the xml to the back end and it gets sucked in to the transform above. I have added the saxon9pe.jar to the lib directory of the Orbeon web application which runs under tomcat.

Regards
 
Old February 17th, 2010, 10:18 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Use
Code:
xmlns:saxon="http://saxon.sf.net/"
.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 17th, 2010, 10:19 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The saxon namespace is http://saxon.sf.net/ as Micheal already said. This should be included in your XSLT as follows:

xmlns:saxon="http://saxon.sf.net/"
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 17th, 2010, 08:59 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

If you look at the xsl code that I posted you will see that I have the namespace correct.

Any other ideas?
 
Old February 17th, 2010, 09:04 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

I figured it out, saxon9pe was not being recognized by orbeon. Thanks for all your help
 
Old February 19th, 2010, 01:45 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

I ended up not using saxon in the end. I wrote a function that stripped out all the escaped markup and replaced with < and > . It was easy to write in java just a couple of replace functions used. Didn't even think about it until the end. Thanks for all your help





Similar Threads
Thread Thread Starter Forum Replies Last Post
Escaped CDATA - outputting HTML mattisimo XSLT 8 February 3rd, 2010 11:01 AM
Accessing and using an ActiveX from inside a HTML page hosted inside a WebBrowser con adyrotaru C# 2005 2 June 25th, 2009 04:21 PM
html part inside xml RoeZ XSLT 3 November 28th, 2007 08:18 AM
Rendering HTML inside XML through XSL - HELP !!! jilly XSLT 6 May 23rd, 2007 10:36 AM
viewing xml inside an html file Tomi XML 1 August 2nd, 2006 05:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.