Project

Profile

Help

Line feed characters

Added by Anonymous over 19 years ago

Legacy ID: #3287258 Legacy Poster: Brendan (august354)

Saxon and/or the operating system adds unrequested line feed characters to output. I have a schema with 4,106 element definitions. A simple transform will list the element names (this will eventually be a comma separated file for import into a database). If I leave the default namespace declaration in the xsd file and declare the same namespace in the xslt file and include a ... <text> </text> ... element to add a line feed to the output I get the desired output with a linefeed after each name. Before I learned of both the need to add the namespace to the xslt file and the line feed character within the <text> element, I would remove the default namespace declaration from the xsd file before the transformation. When this happened, Saxon (8.5) and or Windows XP would add its own linefeed character after each name. (Incidentally, if I left the default namespace declaration in the xsd file and did not add it to the xslt file I would end up with 4,106 blank lines. I do not understand why, when there is no namespace declaration in the xslt file, each visit to an element type element by the xslt processor would generate a linefeed in the output.) If it is Saxon that adds the linefeed, how can I predict when it will do so? Thank you for any comment you may wish to make. I downloaded Saxon the other day and I am new to installation of a Java application. I guessed that I should unzip the downloaded file and run Saxon from the directory the files were extracted to, and everything seems to be working fine. The unpredictable linefeed is not causing me a problem at the moment, but I can see that it might down the line. Later, if I cannot work out how to do it myself from either the Saxon documentation or the Microsoft Access documentation, I may need to ask (probably elsewhere would be appropriate) if it is possible to call Saxon from within a Visual Basic for Applications module.


Replies (5)

Please register to reply

RE: Line feed characters - Added by Anonymous over 19 years ago

Legacy ID: #3287292 Legacy Poster: Brendan (august354)

I have just read another message where the lack of the source code was mentioned, so I think I should supply it. The following is my current version of the xslt file i.e. where the default namespace of the xsd file is declared here too. <?xml version='1.0'?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsl:template match="/xsd:schema"> <!-- "schema" instead of "/" so count function will work --> <xsl:apply-templates select="xsd:element"/> <xsl:value-of select="count(xsd:element)"/> </xsl:template> <xsl:template match="xsd:element"> <xsl:value-of select="./@name"/> <!-- line feed character --> <xsl:text> </xsl:text> </xsl:template> </xsl:stylesheet> An extract from the xsd file is: <?xml version="1.0" encoding="utf-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ifrs-gp="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15" xmlns:ifrs-gp-typ="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15/types" targetNamespace="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15" elementFormDefault="qualified" attributeFormDefault="unqualified"> <import namespace="http://www.xbrl.org/2003/instance" schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd" /> <import namespace="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15/types" schemaLocation="ifrs-gp-types-2005-05-15.xsd" /> <element id="ifrs-gp_AbandonmentOrWithdrawalFromPlanPreviouslyReportedAsDiscontinued" name="AbandonmentOrWithdrawalFromPlanPreviouslyReportedAsDiscontinued" type="xbrli:stringItemType" substitutionGroup="xbrli:item" xbrli:periodType="duration" nillable="true" /> <element id="ifrs-gp_AccountingForAssociatesInConsolidatedAccountsPolicy" name="AccountingForAssociatesInConsolidatedAccountsPolicy" type="xbrli:stringItemType" substitutionGroup="xbrli:item" xbrli:periodType="duration" nillable="true" /> etc. - Brendan

RE: Line feed characters - Added by Anonymous over 19 years ago

Legacy ID: #3289436 Legacy Poster: Michael Kay (mhkay)

You've given me the version of the stylesheet that works, which isn't much use to me - I need the version that doesn't work. There are three ways unwanted whitespace can get into your result document: * the stylesheet generates it * it's copied from the source document * it's generated because the output method implicitly or explicitly uses indent="yes". Saxon never writes whitespace unless you ask for it in one of these three ways. I think you're generating text output here, so start with <xsl:output method="text"/> Michael Kay

RE: Line feed characters - Added by Anonymous over 19 years ago

Legacy ID: #3289550 Legacy Poster: Brendan (august354)

Ouch! and of course you are right :) Sorry for not doing that. *********** <?xml version='1.0'?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="element"> <xsl:value-of select="./@name"/> </xsl:template> </xsl:stylesheet> *********** Running the above style sheet (test5.xslt) on the following xsd file (test2.xsd) will give me blank lines. ************ <?xml version="1.0" encoding="utf-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ifrs-gp="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15" xmlns:ifrs-gp-typ="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15/types" targetNamespace="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15" elementFormDefault="qualified" attributeFormDefault="unqualified"> <import namespace="http://www.xbrl.org/2003/instance" schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd" /> <import namespace="http://xbrl.iasb.org/int/fr/ifrs/gp/2005-05-15/types" schemaLocation="ifrs-gp-types-2005-05-15.xsd" /> <element id="ifrs-gp_AbandonmentOrWithdrawalFromPlanPreviouslyReportedAsDiscontinued" name="AbandonmentOrWithdrawalFromPlanPreviouslyReportedAsDiscontinued" type="xbrli:stringItemType" substitutionGroup="xbrli:item" xbrli:periodType="duration" nillable="true" /> <element id="ifrs-gp_AccountingForAssociatesInConsolidatedAccountsPolicy" name="AccountingForAssociatesInConsolidatedAccountsPolicy" type="xbrli:stringItemType" substitutionGroup="xbrli:item" xbrli:periodType="duration" nillable="true" /> </schema> ************ Running it on the same xsd file except with the declaration [xmlns="http://www.w3.org/2001/XMLSchema"] removed (test3.xsd) gives me a list with each element name on a separate line (with a series of blank lines before the first element name). I was actually not able to replicate the same behaviour with what I thought would be my original style sheet. It made me wonder if I was not reading the screen properly last time (but I was), especially when I have found out I had downloaded (and am using) saxonb8-4 instead of saxonb8-5. I have found however, that the above template, though not my original, replicates the behaviour I experienced. I’m afraid neither indent=”no” nor method=”text” changes the results. I trust you get the same results. (P.S. I'm not sure why extra semi-colons were added to my previous xsd extract, but I imagine it is something you be familiar with assuming it is sourceforge that adds them).

RE: Line feed characters - Added by Anonymous over 19 years ago

Legacy ID: #3290858 Legacy Poster: Michael Kay (mhkay)

The built-in template that matches the <schema> element does an apply-templates to all the children of the <schema> element, that is, to the top-level elements such as <element> and to the whitespace text nodes between these elements. The built-in template for text nodes copies them to the result. This accounts for the whitespace you are seeing in the result. If you aren't interested in the whitespace text nodes in the source document then it's best to get rid of them using <xsl:strip-space elements="*"/>. Michael Kay

RE: Line feed characters - Added by Anonymous over 19 years ago

Legacy ID: #3290939 Legacy Poster: Brendan (august354)

Fascinating. Thank you. It would seem a style sheet author would need to prevent (or allow depending on circumstances) the “built-in template for text nodes” from being invoked, or of course to do as you say, to use <xsl:strip-space elements="*"/>. Thank you very much.

    (1-5/5)

    Please register to reply