 |
| 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
|
|
|
|

April 12th, 2006, 07:26 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Strip the XML file header data from output
My XSL file
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version = "1.0">
<xsl:output method="text"/>
<xsl:template match="Records">
<xsl:apply-templates select="Record"/>
</xsl:template>
<xsl:template match="Record">
<xsl:value-of select="App_Content/OnlineApps/AppType/DragonDirect/DDAppDetails/NoOfApplicants"/>,<xsl:value-of select="App_Content/OnlineApps/AppType/DragonDirect/DDAppDetails/IsBankCustomer"/>,<xsl:value-of select="AppId"/><xsl:value-of select="'#xA;'"/>
</xsl:template>
</xsl:stylesheet>
My XML File
<Records>
<Record>
<AppId>286401</AppId>
<App_Status>SUB</App_Status>
<App_Created>2004-12-14 13:38:40.413</App_Created>
<App_Updated>2005-10-21 18:16:06.273</App_Updated>
<App_Content>
<OnlineApps>
<Version>
<VersionNumber>4.1</VersionNumber>
<VersionDate>23-11-2003</VersionDate>
</Version>
<AppType>
<DragonDirect>
<DDAppDetails>
<NoOfApplicants>1</NoOfApplicants>
<IsBankCustomer>No</IsBankCustomer>
</DDAppDetails>
</DragonDirect>
</AppType>
</OnlineApps>
</App_Content>
</Record>
<Record>
<AppId>286357</AppId>
<App_Status>SUB</App_Status>
<App_Created>2004-12-14 18:02:01.383</App_Created>
<App_Updated>2004-12-14 18:02:57.650</App_Updated>
<App_Content>
<OnlineApps>
<Version>
<VersionNumber>4.1</VersionNumber>
<VersionDate>23-11-2003</VersionDate>
</Version>
<AppType>
<DragonDirect>
<DDAppDetails>
<NoOfApplicants>1</NoOfApplicants>
<IsBankCustomer>No</IsBankCustomer>
</DDAppDetails>
</DragonDirect>
</AppType>
</OnlineApps>
</App_Content>
</Record>
<RecordCount>2</RecordCount>
</Records>
My output is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1,No,286401
1,No,286357
My Question
How do i remove the <?xml version="1.0" encoding="UTF-8" standalone="no"?> from my output. Is there any way to enhance my XSL file. PLS Note:The output data is not fetched sequentially
|
|

April 12th, 2006, 07:34 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
No XML declaration should be written when you specify <xsl:output method="text"/>.
What XSLT processor are you using and how are you invoking it?
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 12th, 2006, 07:46 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using XALAN XSLT Processor and invoking it using java. TransformerFactory tFactory = TransformerFactory.newInstance();
I am not sure about the invocation though
Thanks
Thomas
|
|

April 12th, 2006, 07:49 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Actually I know this one:)
Transformer transformer = transformation.newTransformer();
Properties props = new Properties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperties(props);
|
|

April 12th, 2006, 09:23 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
It would be useful to see what parameters you supply to the transform() method and whether you call setOutputProperties.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 12th, 2006, 09:24 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
omit-xml-declaration shouldn't make any difference with output method text: there shouldn't be an XML declaration anyway.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

April 12th, 2006, 09:42 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Arthur and Micheal. Arthur's setting OMIT_XML_DECLARATION did the trick
Cheers
Thomas
|
|

April 12th, 2006, 09:47 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is there any way to enhance the xsl file, I need to display about 150 element values in one row. The values are not distributed sequentially.Anyway to better the xsl.
eg:
1,No,286401...150 such fields
1,No,286357..150 such fields
Thanks
Thomas
|
|
 |