473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Transforming XML to text (and output tab and new line characters

Apparently .NET strips these white space characters (MSXML doesn't)
regardless of what the output method is set to. I'm using
<xsl:text> </xsl:text> to output a tab character and
<xsl:text> </xsl:text> to output a carriage return and line feed
but they get stripped at some point. I'm passing a StringWriter to the
XslTransform.Transform method. Anyway to get this to actually output the
tab and carriage and line feed characters?
Nov 17 '05 #1
2 3016

"swapna guddanti [MSFT]" <sw*****@microsoft.com> wrote in message
news:43********@news.microsoft.com...

"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
Apparently .NET strips these white space characters (MSXML doesn't)
regardless of what the output method is set to. I'm using
<xsl:text> </xsl:text> to output a tab character and
<xsl:text> </xsl:text> to output a carriage return and line feed but they get stripped at some point. I'm passing a StringWriter to the
XslTransform.Transform method. Anyway to get this to actually output the tab and carriage and line feed characters?

If you include whitespace or carriage return inside <xsl:text> constructs,
this is considered significant whitespace and will not get stripped unless
you have a <xsl:strip-space> in your xslt file.I'm not able to repro this
scenario with StringWriter. Could you please provide more details.
thanks,
swapna


What other detail would you like? I'm tranforming like this:

StringWriter xsw = new StringWriter();

m_Transform.Transform(m_DataDocument, null, xsw, null);

It strips my characters everytime and I've tried different xsl:output
settings to get it to preserve them. I don not have <xsl:strip-space> in my
document.
Here's the full stylesheet:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:aspdnsf="http://www.aspdotnetstorefront.com">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"
encoding="utf-8"/>

<xsl:template match="/">
<xsl:apply-templates select="root/Products/Product" />
</xsl:template>

<xsl:template match="Product">
<xsl:value-of select="SKU" />
<xsl:text> </xsl:text>
<xsl:value-of select="Manufacturer" />
<xsl:text> </xsl:text>
<xsl:value-of select="''" />
<xsl:text> </xsl:text>
<xsl:value-of select="ProductName" />
<xsl:if test="VariantName!=''">
<xsl:value-of select="concat(' - ', VariantName)" />
</xsl:if>
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="FroogleDescription!=''">
<xsl:value-of select="FroogleDescription" />
</xsl:when>
<xsl:when test="ProductFroogleDescription=''">
<xsl:value-of select="ProductFroogleDescription" />
</xsl:when>
<xsl:when test="/root/configs/config/UseDecr='true' and
VariantDescr!=''">
<xsl:value-of select="VariantDescr" />
</xsl:when>
<xsl:when test="/root/configs/config/UseDecr='true' and
ProductDescr!=''">
<xsl:value-of select="ProductDescr" />
</xsl:when>
</xsl:choose>
<xsl:value-of select="price" />
<xsl:text> </xsl:text>
<xsl:value-of select="/root/System/StoreUrl" />(!ProductLink
ProductID=&apos;<xsl:value-of select="ProductID"/>'&apos;
IncludeATag=&apos;false&apos; !)
<xsl:text> </xsl:text>
(!ImageUrl Type=&apos;product&apos; ID=&apos;<xsl:value-of
select="ProductID"/>&apos; Size=&apos;icon&apos; FullUrl=&apos;true&apos; !)
<xsl:text> </xsl:text>
<xsl:value-of select="'Auto Parts and Accessories'" />
<xsl:text> </xsl:text>
<xsl:value-of select="'Y'" />
<xsl:text> </xsl:text>
<xsl:value-of select="'Ships 2-4 days'" />
<xsl:text> </xsl:text>
<xsl:value-of select="ShippingCharge" />
<xsl:text> </xsl:text>
<xsl:value-of select="weight" />
<xsl:text> </xsl:text>
<xsl:value-of select="'91304'" />
<xsl:text> </xsl:text>
</xsl:template>

</xsl:stylesheet>
Nov 26 '05 #2
The problem is not in .Transform() but in the way how you call .Load().
Nost likely you load XSLT to XPathDocument or XmlDocument and it strips all
white space nodes. To disable WS stripping in XPathDocument you can pass it
XmlSpace.Preserve as an argulemt.

To verify that WS stripping is the root of the problem add
xml:space="preserve" attribute into <xsl:text> element.

Sergey

"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

"swapna guddanti [MSFT]" <sw*****@microsoft.com> wrote in message
news:43********@news.microsoft.com...

"Buddy Ackerman" <bu**********@buddyackerman.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
> Apparently .NET strips these white space characters (MSXML doesn't)
> regardless of what the output method is set to. I'm using
> <xsl:text> </xsl:text> to output a tab character and
> <xsl:text> </xsl:text> to output a carriage return and line feed > but they get stripped at some point. I'm passing a StringWriter to the
> XslTransform.Transform method. Anyway to get this to actually output the > tab and carriage and line feed characters?
>
>

If you include whitespace or carriage return inside <xsl:text>
constructs,
this is considered significant whitespace and will not get stripped
unless
you have a <xsl:strip-space> in your xslt file.I'm not able to repro this
scenario with StringWriter. Could you please provide more details.
thanks,
swapna


What other detail would you like? I'm tranforming like this:

StringWriter xsw = new StringWriter();

m_Transform.Transform(m_DataDocument, null, xsw, null);

It strips my characters everytime and I've tried different xsl:output
settings to get it to preserve them. I don not have <xsl:strip-space> in
my
document.
Here's the full stylesheet:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:aspdnsf="http://www.aspdotnetstorefront.com">
<xsl:output method="text" omit-xml-declaration="yes"
indent="no"
encoding="utf-8"/>

<xsl:template match="/">
<xsl:apply-templates select="root/Products/Product" />
</xsl:template>

<xsl:template match="Product">
<xsl:value-of select="SKU" />
<xsl:text> </xsl:text>
<xsl:value-of select="Manufacturer" />
<xsl:text> </xsl:text>
<xsl:value-of select="''" />
<xsl:text> </xsl:text>
<xsl:value-of select="ProductName" />
<xsl:if test="VariantName!=''">
<xsl:value-of select="concat(' - ', VariantName)" />
</xsl:if>
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="FroogleDescription!=''">
<xsl:value-of select="FroogleDescription" />
</xsl:when>
<xsl:when test="ProductFroogleDescription=''">
<xsl:value-of select="ProductFroogleDescription" />
</xsl:when>
<xsl:when test="/root/configs/config/UseDecr='true' and
VariantDescr!=''">
<xsl:value-of select="VariantDescr" />
</xsl:when>
<xsl:when test="/root/configs/config/UseDecr='true' and
ProductDescr!=''">
<xsl:value-of select="ProductDescr" />
</xsl:when>
</xsl:choose>
<xsl:value-of select="price" />
<xsl:text> </xsl:text>
<xsl:value-of select="/root/System/StoreUrl"
/>(!ProductLink
ProductID=&apos;<xsl:value-of select="ProductID"/>'&apos;
IncludeATag=&apos;false&apos; !)
<xsl:text> </xsl:text>
(!ImageUrl Type=&apos;product&apos; ID=&apos;<xsl:value-of
select="ProductID"/>&apos; Size=&apos;icon&apos; FullUrl=&apos;true&apos;
!)
<xsl:text> </xsl:text>
<xsl:value-of select="'Auto Parts and Accessories'" />
<xsl:text> </xsl:text>
<xsl:value-of select="'Y'" />
<xsl:text> </xsl:text>
<xsl:value-of select="'Ships 2-4 days'" />
<xsl:text> </xsl:text>
<xsl:value-of select="ShippingCharge" />
<xsl:text> </xsl:text>
<xsl:value-of select="weight" />
<xsl:text> </xsl:text>
<xsl:value-of select="'91304'" />
<xsl:text> </xsl:text>
</xsl:template>

</xsl:stylesheet>

Dec 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mikeyjudkins | last post by:
I have an XML file containing localized strings in 9 languages, encoded in Unicode (UTF-8). Im trying to parse this XML document via XSLT (Apache Xalan) to selectively render localized strings...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
8
by: FUGATO | last post by:
I need to help in my assignment. I need to wrap a text with the following indications: 1.If you have reached the end of the line (number of characters on this line >= 40) AND you have reached the...
10
by: Kenneth Brody | last post by:
I recently ran into an "issue" related to text files and ftell/fseek, and I'd like to know if it's a bug, or simply an annoying, but still conforming, implementation. The platform is Windows,...
5
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now...
0
by: buzzw | last post by:
Hi I have a wraptext procedure which accepts input text and fits it within given output length . Following is my test script Accept line Prompt 'enter text : ' Accept len prompt 'enter length...
1
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.