Discussion:
Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
Pankaj Chaturvedi
2008-09-23 22:51:57 UTC
Permalink
In my stylesheet, I am stripping all the spaces, new line character while
using <xsl:strip-space elements="*"/> which works perfectly as desired.

But now I've come across the requirement where I need to preserve spaces
between the tags in few specific elements generally the punctuations(see
below example) I tried to use the <xsl:preserve-space> to sort out this
issue but doesn't seems to be working and "xsl:strip-space" seems to
overcoming the effect of "xsl:preserve-space" effects. Can we use both to
get their respective effects or simply they cannot be used together?

Below is how they looks in my stylesheet:

Snippet
=======

<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:strip-space elements="*"/>

<xsl:preserve-space elements="element1 element2"/>

<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>

--------------
--------------
--------------
--------------
--------------

</xsl:stylesheet>


Example:

<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>&ndash;<last-page>46</last-page>.</element1>

Note: Spaces between the tags with any punctuation appears correctly (like
in <surname>Dajnoki</surname>, <givenname>K.</givenname>) but fails in case
of a single space between tags > < (for instance in </journal-title>
<first-page> and results into the </journal-title><first-page> )


Below is how I have defined template for "element1"

<xsl:template match="element1">
<xsl:apply-templates/>
</xsl:template>

Any suggestion would be an immense help.


Best,

Pankaj Chaturvedi

============================================================================
================


Confidentiality Notice:" This message and any attachment(s)
contained here are information that is confidential, proprietary to
IDS Infotech Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the entity it
is addressed to. If you are not the intended recipient of this
message, you are not authorized to read, forward, print, retain,
copy or disseminate this message or any part of it. If you have
received this e-mail in error, please notify the sender immediately
by return e-mail and delete it from your computer."

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Michael Kay
2008-09-24 07:14:34 UTC
Permalink
What XML parser and XSLT processor are you using?

Michael Kay
http://www.saxonica.com/
-----Original Message-----
Sent: 23 September 2008 23:52
Subject: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
In my stylesheet, I am stripping all the spaces, new line
character while using <xsl:strip-space elements="*"/> which
works perfectly as desired.
But now I've come across the requirement where I need to
preserve spaces between the tags in few specific elements
generally the punctuations(see below example) I tried to use
the <xsl:preserve-space> to sort out this issue but doesn't
seems to be working and "xsl:strip-space" seems to overcoming
the effect of "xsl:preserve-space" effects. Can we use both
to get their respective effects or simply they cannot be used
together?
Snippet
=======
<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:strip-space elements="*"/>
<xsl:preserve-space elements="element1 element2"/>
<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>
--------------
--------------
--------------
--------------
--------------
</xsl:stylesheet>
<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>&ndash;<last-page>46</last-page>.</
element1>
Note: Spaces between the tags with any punctuation appears
correctly (like in <surname>Dajnoki</surname>,
<givenname>K.</givenname>) but fails in case of a single
space between tags > < (for instance in </journal-title>
<first-page> and results into the </journal-title><first-page> )
Below is how I have defined template for "element1"
<xsl:template match="element1">
<xsl:apply-templates/>
</xsl:template>
Any suggestion would be an immense help.
Best,
Pankaj Chaturvedi
==============================================================
==============
================
Confidentiality Notice:" This message and any attachment(s)
contained here are information that is confidential,
proprietary to IDS Infotech Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the
entity it is addressed to. If you are not the intended
recipient of this message, you are not authorized to read,
forward, print, retain, copy or disseminate this message or
any part of it. If you have received this e-mail in error,
please notify the sender immediately by return e-mail and
delete it from your computer."
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Pankaj Chaturvedi
2008-09-24 07:30:37 UTC
Permalink
Michael Kay wrote:

What XML parser and XSLT processor are you using?


I am using Altova's XML Spy Enterprise edition (version 2008 sp1) and using
its "Built-in XSLT Engine".

Pankaj
-----Original Message-----
Sent: 23 September 2008 23:52
Subject: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
In my stylesheet, I am stripping all the spaces, new line character
while using <xsl:strip-space elements="*"/> which works perfectly as
desired.
But now I've come across the requirement where I need to preserve
spaces between the tags in few specific elements generally the
punctuations(see below example) I tried to use the
<xsl:preserve-space> to sort out this issue but doesn't seems to be
working and "xsl:strip-space" seems to overcoming the effect of
"xsl:preserve-space" effects. Can we use both to get their respective
effects or simply they cannot be used together?
Snippet
=======
<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:strip-space elements="*"/>
<xsl:preserve-space elements="element1 element2"/>
<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>
--------------
--------------
--------------
--------------
--------------
</xsl:stylesheet>
<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>&ndash;<last-page>46</last-page>.</
element1>
Note: Spaces between the tags with any punctuation appears correctly
(like in <surname>Dajnoki</surname>,
<givenname>K.</givenname>) but fails in case of a single space
between tags > < (for instance in </journal-title> <first-page> and
results into the </journal-title><first-page> )
Below is how I have defined template for "element1"
<xsl:template match="element1">
<xsl:apply-templates/>
</xsl:template>
Any suggestion would be an immense help.
Best,
Pankaj Chaturvedi
==============================================================
==============
================
Confidentiality Notice:" This message and any attachment(s) contained
here are information that is confidential, proprietary to IDS Infotech
Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the entity it is
addressed to. If you are not the intended recipient of this message,
you are not authorized to read, forward, print, retain, copy or
disseminate this message or any part of it. If you have received this
e-mail in error, please notify the sender immediately by return e-mail
and delete it from your computer."
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Pankaj Chaturvedi
2008-09-24 08:51:38 UTC
Permalink
What XML parser and XSLT processor are you using?


Just for curiosity Michael, is this related with XSLT processor or there is
error in my code.

Thanks for help.

Pankaj
-----Original Message-----
Sent: 23 September 2008 23:52
Subject: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
In my stylesheet, I am stripping all the spaces, new line character
while using <xsl:strip-space elements="*"/> which works perfectly as
desired.
But now I've come across the requirement where I need to preserve
spaces between the tags in few specific elements generally the
punctuations(see below example) I tried to use the
<xsl:preserve-space> to sort out this issue but doesn't seems to be
working and "xsl:strip-space" seems to overcoming the effect of
"xsl:preserve-space" effects. Can we use both to get their respective
effects or simply they cannot be used together?
Snippet
=======
<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:strip-space elements="*"/>
<xsl:preserve-space elements="element1 element2"/>
<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>
--------------
--------------
--------------
--------------
--------------
</xsl:stylesheet>
<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>&ndash;<last-page>46</last-page>.</
element1>
Note: Spaces between the tags with any punctuation appears correctly
(like in <surname>Dajnoki</surname>,
<givenname>K.</givenname>) but fails in case of a single space
between tags > < (for instance in </journal-title> <first-page> and
results into the </journal-title><first-page> )
Below is how I have defined template for "element1"
<xsl:template match="element1">
<xsl:apply-templates/>
</xsl:template>
Any suggestion would be an immense help.
Best,
Pankaj Chaturvedi
==============================================================
==============
================
Confidentiality Notice:" This message and any attachment(s) contained
here are information that is confidential, proprietary to IDS Infotech
Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the entity it is
addressed to. If you are not the intended recipient of this message,
you are not authorized to read, forward, print, retain, copy or
disseminate this message or any part of it. If you have received this
e-mail in error, please notify the sender immediately by return e-mail
and delete it from your computer."
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
David Carlisle
2008-09-24 09:22:53 UTC
Permalink
Post by Pankaj Chaturvedi
Just for curiosity Michael, is this related with XSLT processor or there is
error in my code.
It's microsoft's xml parser that has an "optimisation" in that it
removes all white sppace nodes by default and does this at xml parse
time, before xslt or any other process sees the result, so you can not
preserve the spaces, they have already gone.

The parser has a preserveWhitespace property that you can set to true
before parsing which will make the parser conform to the xml spec and
report these spaces, but I don't know if xml spy gives you an interface
to setting that property.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Michael Kay
2008-09-24 13:05:37 UTC
Permalink
I believe it's true that the AltovaXML processor always strips whitespace
nodes (or calls the MSXML parser in a way that strips them) and I'm not
aware of any way of changing this.

Michael Kay
http://www.saxonica.com/
-----Original Message-----
Sent: 24 September 2008 09:52
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
What XML parser and XSLT processor are you using?
Just for curiosity Michael, is this related with XSLT
processor or there is error in my code.
Thanks for help.
Pankaj
-----Original Message-----
Sent: 23 September 2008 23:52
Subject: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
In my stylesheet, I am stripping all the spaces, new line character
while using <xsl:strip-space elements="*"/> which works
perfectly as
desired.
But now I've come across the requirement where I need to preserve
spaces between the tags in few specific elements generally the
punctuations(see below example) I tried to use the
<xsl:preserve-space> to sort out this issue but doesn't seems to be
working and "xsl:strip-space" seems to overcoming the effect of
"xsl:preserve-space" effects. Can we use both to get their
respective
effects or simply they cannot be used together?
Snippet
=======
<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:strip-space elements="*"/>
<xsl:preserve-space elements="element1 element2"/>
<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>
--------------
--------------
--------------
--------------
--------------
</xsl:stylesheet>
<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>&ndash;<last-page>46</last-page>.</
element1>
Note: Spaces between the tags with any punctuation appears
correctly
(like in <surname>Dajnoki</surname>,
<givenname>K.</givenname>) but fails in case of a single space
between tags > < (for instance in </journal-title> <first-page> and
results into the </journal-title><first-page> )
Below is how I have defined template for "element1"
<xsl:template match="element1">
<xsl:apply-templates/>
</xsl:template>
Any suggestion would be an immense help.
Best,
Pankaj Chaturvedi
==============================================================
==============
================
Confidentiality Notice:" This message and any attachment(s)
contained
here are information that is confidential, proprietary to
IDS Infotech
Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the
entity it is
addressed to. If you are not the intended recipient of this
message,
you are not authorized to read, forward, print, retain, copy or
disseminate this message or any part of it. If you have
received this
e-mail in error, please notify the sender immediately by
return e-mail
and delete it from your computer."
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Pankaj Chaturvedi
2008-09-24 13:18:56 UTC
Permalink
Not a good news for me.

Well anyways David/Michael thanks for looking into this.


Best,

Pankaj Chaturvedi

============================================================================
================


-----Original Message-----
From: Michael Kay [mailto:***@saxonica.com]
Sent: Wednesday, September 24, 2008 6:36 PM
To: xsl-***@lists.mulberrytech.com
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)


I believe it's true that the AltovaXML processor always strips whitespace
nodes (or calls the MSXML parser in a way that strips them) and I'm not
aware of any way of changing this.

Michael Kay
http://www.saxonica.com/
-----Original Message-----
Sent: 24 September 2008 09:52
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
What XML parser and XSLT processor are you using?
Just for curiosity Michael, is this related with XSLT processor or
there is error in my code.
Thanks for help.
Pankaj
-----Original Message-----
Sent: 23 September 2008 23:52
Subject: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
In my stylesheet, I am stripping all the spaces, new line character
while using <xsl:strip-space elements="*"/> which works
perfectly as
desired.
But now I've come across the requirement where I need to preserve
spaces between the tags in few specific elements generally the
punctuations(see below example) I tried to use the
<xsl:preserve-space> to sort out this issue but doesn't seems to be
working and "xsl:strip-space" seems to overcoming the effect of
"xsl:preserve-space" effects. Can we use both to get their
respective
effects or simply they cannot be used together?
Snippet
=======
<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:strip-space elements="*"/>
<xsl:preserve-space elements="element1 element2"/>
<xsl:output encoding="UTF-8" indent="no" media-type="text/xml"
method="xml"/>
--------------
--------------
--------------
--------------
--------------
</xsl:stylesheet>
<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>&ndash;<last-page>46</last-page>.</
element1>
Note: Spaces between the tags with any punctuation appears
correctly
(like in <surname>Dajnoki</surname>,
<givenname>K.</givenname>) but fails in case of a single space
between tags > < (for instance in </journal-title> <first-page> and
results into the </journal-title><first-page> )
Below is how I have defined template for "element1"
<xsl:template match="element1">
<xsl:apply-templates/>
</xsl:template>
Any suggestion would be an immense help.
Best,
Pankaj Chaturvedi
==============================================================
==============
================
Confidentiality Notice:" This message and any attachment(s)
contained
here are information that is confidential, proprietary to
IDS Infotech
Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the
entity it is
addressed to. If you are not the intended recipient of this
message,
you are not authorized to read, forward, print, retain, copy or
disseminate this message or any part of it. If you have
received this
e-mail in error, please notify the sender immediately by
return e-mail
and delete it from your computer."
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Evan Lenz
2008-09-24 16:31:12 UTC
Permalink
Pankaj,

You can force MSXML to preserve whitespace by adding
xml:space="preserve" to the root element of your document. Then your
original stylesheet should work as desired. Let me know if that works.

Evan
Post by Pankaj Chaturvedi
Not a good news for me.
Well anyways David/Michael thanks for looking into this.
Best,
Pankaj Chaturvedi
============================================================================
================
-----Original Message-----
Sent: Wednesday, September 24, 2008 6:36 PM
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
I believe it's true that the AltovaXML processor always strips whitespace
nodes (or calls the MSXML parser in a way that strips them) and I'm not
aware of any way of changing this.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Evan Lenz
2008-09-24 16:54:50 UTC
Permalink
On second thought, your original stylesheet will have to change, because
<xsl:strip-space/> won't strip whitespace-only text nodes that have been
force-preserved using xml:space="preserve" (which will be true for all
whitespace in your document if you put that at the root element).

Instead of using <xsl:strip-space/> (and <xsl:preserve-space/>), you
could use a template rule that processes whitespace-only text nodes that
are not children of <element1> or <element2>:

<xsl:template match="*[not(self::element1 or
self::element2)]/text()[not(normalize-space())]"/>

The rule is empty and thus has the effect of "stripping" them from the
result.

Let me know if that works. :-)

Evan
Post by Evan Lenz
Pankaj,
You can force MSXML to preserve whitespace by adding
xml:space="preserve" to the root element of your document. Then your
original stylesheet should work as desired. Let me know if that works.
Evan
Post by Pankaj Chaturvedi
Not a good news for me.
Well anyways David/Michael thanks for looking into this.
Best,
Pankaj Chaturvedi
============================================================================
================
-----Original Message-----
September 24, 2008 6:36 PM
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
I believe it's true that the AltovaXML processor always strips whitespace
nodes (or calls the MSXML parser in a way that strips them) and I'm not
aware of any way of changing this.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Evan Lenz
2008-09-24 17:52:58 UTC
Permalink
I got a message off-list that suggested to me that I wasn't very clear
about this. To be clear, the template-rule approach below requires that
you have xml:space="preserve" in the source document to prevent MSXML
from stripping any whitespace. Of course, as a stylesheet writer, that
may not always be within your control. But one way or another, you need
to preserve whitespace, and I can only think of three ways to do that:

1. Use xml:space="preserve" in the source document,
2. Set the preserveWhiteSpace property to true in the MSXML API, or
3. Use a different XSLT processor.

A variation of #1 is to simply put xml:space="preserve" on all the
<element1> and <element2> elements, but that might not be as practical.

Evan
Post by Evan Lenz
On second thought, your original stylesheet will have to change,
because <xsl:strip-space/> won't strip whitespace-only text nodes that
have been force-preserved using xml:space="preserve" (which will be
true for all whitespace in your document if you put that at the root
element).
Instead of using <xsl:strip-space/> (and <xsl:preserve-space/>), you
could use a template rule that processes whitespace-only text nodes
<xsl:template match="*[not(self::element1 or
self::element2)]/text()[not(normalize-space())]"/>
The rule is empty and thus has the effect of "stripping" them from the
result.
Let me know if that works. :-)
Evan
Post by Evan Lenz
Pankaj,
You can force MSXML to preserve whitespace by adding
xml:space="preserve" to the root element of your document. Then your
original stylesheet should work as desired. Let me know if that works.
Evan
Post by Pankaj Chaturvedi
Not a good news for me.
Well anyways David/Michael thanks for looking into this.
Best,
Pankaj Chaturvedi
============================================================================
================
-----Original Message-----
September 24, 2008 6:36 PM
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
I believe it's true that the AltovaXML processor always strips whitespace
nodes (or calls the MSXML parser in a way that strips them) and I'm not
aware of any way of changing this.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Pankaj Chaturvedi
2008-09-25 07:11:45 UTC
Permalink
<xsl:template match="*[not(self::element1 or
self::element2)]/text()[not(normalize-space())]"/>
Let me know if that works. :-)


Thanks Evan. I will check and let you know.

Pankaj
Post by Evan Lenz
Pankaj,
You can force MSXML to preserve whitespace by adding
xml:space="preserve" to the root element of your document. Then your
original stylesheet should work as desired. Let me know if that works.
Evan
Post by Pankaj Chaturvedi
Not a good news for me.
Well anyways David/Michael thanks for looking into this.
Best,
Pankaj Chaturvedi
=====================================================================
=======
================
-----Original Message-----
September 24, 2008 6:36 PM
Subject: RE: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
I believe it's true that the AltovaXML processor always strips
whitespace nodes (or calls the MSXML parser in a way that strips
them) and I'm not aware of any way of changing this.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--


Confidentiality Notice:" This message and any attachment(s)
contained here are information that is confidential, proprietary to
IDS Infotech Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the entity it
is addressed to. If you are not the intended recipient of this
message, you are not authorized to read, forward, print, retain,
copy or disseminate this message or any part of it. If you have
received this e-mail in error, please notify the sender immediately
by return e-mail and delete it from your computer."

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--

G. Ken Holman
2008-09-24 16:01:04 UTC
Permalink
(retry due to mailer problems from yesterday)

Date: Tue, 23 Sep 2008 16:55:55 -0700
To: <xsl-***@lists.mulberrytech.com>
From: "G. Ken Holman" <***@CraneSoftwrights.com>
Subject: Re: [xsl] Xsl:strip-space and xsl:preserve-space (XSLT 2.0)
Post by Pankaj Chaturvedi
In my stylesheet, I am stripping all the spaces, new line character while
using <xsl:strip-space elements="*"/> which works perfectly as desired.
But have you confirmed that without this statement this is not
already happening?

You don't mention which processor you are using or what invocation
parameters you are using.

In XSLT 1.0 you could rely on the source document white-space-only
text nodes to be preserved (except when using Microsoft). In XSLT
2.0 you cannot rely on this, because the *invocation* of the XSLT
processor can change whether or not white-space-only text nodes in
source documents are preserved.

Note, for example, the invocation of Saxon has the following parameter:

-strip:all|none|ignorable

Here is an example where the white-space between "</journal-title>"
and "<first-page>" is shown to be stripped or preserved without
saying anything in the stylesheet about stripping:

T:\ftemp>type pankaj.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:output method="text"/>

</xsl:stylesheet>
T:\ftemp>type pankaj.xml
<element1><surname>Dajnoki</surname>, <givenname>K.</givenname>
(<year>2002</year>) <article-title>XXXXX YYYY</article-title>.
<journal-title>ZZZZZZ XXXX</journal-title>
<first-page>43</first-page>-<last-page>46</last-page>.</element1>

T:\ftemp>saxon9 -strip:all pankaj.xml pankaj.xsl
Dajnoki, K.
(2002) XXXXX YYYY.
ZZZZZZ XXXX43-46.
T:\ftemp>saxon9 -strip:none pankaj.xml pankaj.xsl
Dajnoki, K.
(2002) XXXXX YYYY.
ZZZZZZ XXXX
43-46.
T:\ftemp>
Post by Pankaj Chaturvedi
But now I've come across the requirement where I need to preserve spaces
between the tags in few specific elements generally the punctuations(see
below example) I tried to use the <xsl:preserve-space> to sort out this
issue but doesn't seems to be working
Perhaps that is because the data model for your document, as created
by your stylesheet processor, is already stripping the
white-space-only text nodes before your stylesheet is invoked.
Post by Pankaj Chaturvedi
and "xsl:strip-space" seems to
overcoming the effect of "xsl:preserve-space" effects. Can we use both to
get their respective effects or simply they cannot be used together?
They can be used together.

Consider the following examples where, in pankaj2.xsl all elements
are having their white-space-only text nodes stripped with
<xsl:strip-space/> but in pankaj3.xsl there is the override with
<xsl:preserve-space/>:

T:\ftemp>type pankaj2.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:strip-space elements="*"/>

<xsl:output method="text"/>

</xsl:stylesheet>
T:\ftemp>saxon9 -strip:none pankaj.xml pankaj2.xsl
Dajnoki, K.
(2002) XXXXX YYYY.
ZZZZZZ XXXX43-46.
T:\ftemp>type pankaj3.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">

<xsl:strip-space elements="*"/>

<xsl:preserve-space elements="element1 element2"/>

<xsl:output method="text"/>

</xsl:stylesheet>
T:\ftemp>saxon9 -strip:none pankaj.xml pankaj3.xsl
Dajnoki, K.
(2002) XXXXX YYYY.
ZZZZZZ XXXX
43-46.
T:\ftemp>

Note: Spaces between the tags with any punctuation appears correctly (like
in <surname>Dajnoki</surname>, <givenname>K.</givenname>) but fails in case
of a single space between tags > < (for instance in </journal-title>
<first-page> and results into the </journal-title><first-page> )

Stripping and preserving white-space-only text nodes do not impact
text nodes that are not white-space-only. When there is punctuation
the node is not white-space-only.

I hope this helps.

. . . . . . . . . . Ken


--
Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
G. Ken Holman mailto:***@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Colin Paul Adams
2008-09-24 16:50:42 UTC
Permalink
Ken> In XSLT 1.0 you could rely on the source document
Ken> white-space-only text nodes to be preserved (except when
Ken> using Microsoft). In XSLT 2.0 you cannot rely on this,
Ken> because the *invocation* of the XSLT processor can change
Ken> whether or not white-space-only text nodes in source
Ken> documents are preserved.

Ken> Note, for example, the invocation of Saxon has the following
Ken> parameter:

Ken> -strip:all|none|ignorable

I can't see any justification for this in the XSLT 2.0 recommendation,
other than the caveat of how a source document is constructed is
outside the remit of the recommendation. That was always the case for
XSLT 1.0 too.
--
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Michael Kay
2008-09-24 20:17:49 UTC
Permalink
Post by Colin Paul Adams
Ken> -strip:all|none|ignorable
I can't see any justification for this in the XSLT 2.0
recommendation, other than the caveat of how a source
document is constructed is outside the remit of the
recommendation.
This switch is nothing to do with the Recommendation, which says processors
can do what they like. There are three common patterns of whitespace
handling: report all whitespace text nodes, report none, and report only
those in element-only content. People come to Saxon from other products and
complain that its default is different from the one assumed by their
stylesheet code; this switch allows you to emulate what your previous
processor did so you don't have to change your code.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Colin Paul Adams
2008-09-25 05:46:47 UTC
Permalink
Ken> -strip:all|none|ignorable
Post by Colin Paul Adams
I can't see any justification for this in the XSLT 2.0
recommendation, other than the caveat of how a source document
is constructed is outside the remit of the recommendation.
Michael> This switch is nothing to do with the Recommendation,
Michael> which says processors can do what they like.


And my point was that this is the same in XSLT 1.0.
--
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Loading...