xslt - Help on converting XML to positional text file without stripping spaces -


i'm trying create positional file out of xml. created xslt , work fine unless field filled spaces. in case xsl returns 1 space. i'm using msxml (6.0).

i have tried following no luck:

<xsl:strip-space elements="*"/> <xsl:preserve-space elements="*"/>  <fo:block white-space-collapse="false" white-space-treatment="preserve" >     <!-- code here --> </fo:block> 

here xml input, xslt , output.

<document>       <header>         <title>long life queen   </title>         <author>sam catnip     </author>         <year>1996</year>         <edition>  1</edition>         <price>          12.99</price>         <pages>    1244</pages>         <authornotes>                    </authornotes>         <abstract>it great book  </abstract>     </header>       <header>         <title>life , live longer     </title>         <author>bill griffin   </author>         <year>2001</year>         <edition>  1</edition>         <price>           2.99</price>         <pages>      44</pages>         <authornotes>yeah, right         </authornotes>         <abstract>wishfull thinking    </abstract>     </header> </document> 

xslt:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:fo="http://www.w3.org/1999/xsl/format" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:fn="http://www.w3.org/2005/xpath-functions">     <xsl:output method="text"/>     <xsl:template match="//document">         <xsl:for-each select="./header">             <xsl:value-of select="./title"/>             <xsl:value-of select="./author"/>             <xsl:value-of select="./year"/>             <xsl:value-of select="./edition"/>             <xsl:value-of select="./price"/>                     <xsl:value-of select="./pages"/>             <xsl:value-of select="./authornotes"/>             <xsl:value-of select="./abstract"/>             <xsl:text>&#13;&#10;</xsl:text>         </xsl:for-each>     </xsl:template> </xsl:stylesheet> 

output:

long life queen   sam catnip     1996  1          12.99    1244it great book   life , live longer     bill griffin   2001  1           2.99      44yeah, right         wishfull thinking     

when should be:

long life queen   sam catnip     1996  1          12.99    1244                    great book   life , live longer     bill griffin   2001  1           2.99      44yeah, right         wishfull thinking     

i appreciate idea on how solve this.

thanks,

arty

even if xslt contains instruction preserve whitespace, might not have been preserved when input xml document parsed before being passed xslt.

you didn't specify language/platform or you're using, it's difficult offer specific solution, know in c# if read xml document this:

string xmlsource = @"<document>etc..</document>"; xmldocument doc = new xmldocument(); doc.loadxml(xmlsource); 

it have treated elements space empty elements, , doc has space stripped out before try applying stylesheet.

in c#, need this:

xmldocument doc = new xmldocument { preservewhitespace = true }; 

when instantiate before loading it. if you're using different platform, you'll need research how platform this.

a more general solution (albeit tad cumbersome) modify input xml this:

...   <authornotes xml:space="preserve">                    </authornotes> ... 

i think can apply root element, i'm not 100% of that.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -