By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,534 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,534 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.