473,238 Members | 1,838 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,238 software developers and data experts.

Removing Tabs from source XML in output from XSLT

I am having this problem...
Lets say that your source XML is formatted like this:
<somenode>
Here is some text
Here is some more text
</somenode>

When to a <xsl:value-of select="somenode" /I want the output to be
free of the tabs that are included in the source XML.
These tabs are not really part of the content, but rather just there
for formatting reasons.

I tried doing:
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
But that didn't seem to have an effect.
Any way to do this?

Jul 29 '06 #1
11 6106
These tabs are not really part of the content, but rather just there
for formatting reasons.
Well, the best answer is not to put them in for formatting, but to
format for humans at the time when humans want to read the data.
However, assuming that you're stuck with them...
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
No, that won't work; translate is strictly a replacement operation, and
can't be used to remove characters.

If you know there's only a single tab, you could use
concat(substring-before(somenode,"&#x9"),
substring-after(somenode,"&#x9"))
If there may be multiple tabs, you need to repeat that until all tabs
have been dealt with -- which in XSLT 1.0 means writing a recursive
named template and invoking it via call-template. (XSLT 2.0 has a
slightly more elegant syntax for writing and calling functions.) I'm
sure there are examples of this approach in the XSLT FAQ, or in many
decent XSLT tutorials.

Or you could invoke a non-XSLT extension function, if your processor
supports that.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 29 '06 #2


cmay wrote:

I tried doing:
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
But that didn't seem to have an effect.
That tab character has code number 9 and a character reference needs to
end with a semicolon so you need
<xsl:value-of select='translate(somenode," ", "")'/>

That should do then in my view, contrary what Joe says, as translate
<http://www.w3.org/TR/xpath#function-translateindeed removes
characters found in the second argument string for which there are no
corresponding positions in the third argument string.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 30 '06 #3
Good catch on the missing semicolon, and yes the removal should work; I
was misremembering. (Sigh. Don't type while tired.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 30 '06 #4
If you're working on a unix platform another simpler alternative may to
run your source xml file through a utility program such as 'detab' or
'entab'?

This would mean that you would not have to use any form of XSL at all
ofcourse.

HTH,

Naran.

cmay wrote:
I am having this problem...
Lets say that your source XML is formatted like this:
<somenode>
Here is some text
Here is some more text
</somenode>

When to a <xsl:value-of select="somenode" /I want the output to be
free of the tabs that are included in the source XML.
These tabs are not really part of the content, but rather just there
for formatting reasons.

I tried doing:
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
But that didn't seem to have an effect.
Any way to do this?
Jul 30 '06 #5
On 30 Jul 2006 05:37:26 -0700, "WideBoy" wrote in comp.text.xml:
>If you're working on a unix platform another simpler alternative may to
run your source xml file through a utility program such as 'detab' or
'entab'?
[snip]

There are numerous versions of detab available for Win32, too.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Jul 30 '06 #6
Thanks for responding guys.
Unfortunately, the typo was just in my newsgroup post, and not in my
code.
I tried it again but the tabs persist.

Even though these are definately tabs in my xml source, I wonder if
they are coming through as spaces somehow.

Anyway thanks for your help.

Chris

Joe Kesselman wrote:
Good catch on the missing semicolon, and yes the removal should work; I
was misremembering. (Sigh. Don't type while tired.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 30 '06 #7
cmay wrote:
I tried it again but the tabs persist.
Are you sure the rest of your stylesheet is reasonable -- ie, that this
expression is indeed being evaluated at the right places?
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 31 '06 #8
If you can use XSLT 2.0 then you can use a character map. Just add the
following lines to your stylesheet and the tabs will be removed from
output:

<xsl:character-map name="test">
<xsl:output-character character=" " string=""/>
</xsl:character-map>
<xsl:output use-character-maps="test"/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

cmay wrote:
I am having this problem...
Lets say that your source XML is formatted like this:
<somenode>
Here is some text
Here is some more text
</somenode>

When to a <xsl:value-of select="somenode" /I want the output to be
free of the tabs that are included in the source XML.
These tabs are not really part of the content, but rather just there
for formatting reasons.

I tried doing:
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
But that didn't seem to have an effect.
Any way to do this?
Jul 31 '06 #9
Yea it turned out that my xml editor was converting tabs to spaces.

I found some option to turn that off and the tab removal translate
function works fine.

Thanks guys!

Joe Kesselman wrote:
cmay wrote:
I tried it again but the tabs persist.

Are you sure the rest of your stylesheet is reasonable -- ie, that this
expression is indeed being evaluated at the right places?
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 31 '06 #10
Thanks George, I didn't know about that option and it looks pretty
good, good thing to know.

Is there anything similar that will allow for replacement of strings in
this manner?

I see that then 2nd parameter can be a string, but everything I have
read indicates that the first parameter "character" must be a single
character and can't be a string.

I'm guessing there isn't anything to do this other than writing your
own function correct?
Chris

George Bina wrote:
If you can use XSLT 2.0 then you can use a character map. Just add the
following lines to your stylesheet and the tabs will be removed from
output:

<xsl:character-map name="test">
<xsl:output-character character=" " string=""/>
</xsl:character-map>
<xsl:output use-character-maps="test"/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

cmay wrote:
I am having this problem...
Lets say that your source XML is formatted like this:
<somenode>
Here is some text
Here is some more text
</somenode>

When to a <xsl:value-of select="somenode" /I want the output to be
free of the tabs that are included in the source XML.
These tabs are not really part of the content, but rather just there
for formatting reasons.

I tried doing:
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
But that didn't seem to have an effect.
Any way to do this?
Jul 31 '06 #11
You cannot replace strings, only characters. The replacement is a
string, for instance if you want to write an entity reference for a
specific character then you can map that character to the string that
represents an entity reference to that character.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

cmay wrote:
Thanks George, I didn't know about that option and it looks pretty
good, good thing to know.

Is there anything similar that will allow for replacement of strings in
this manner?

I see that then 2nd parameter can be a string, but everything I have
read indicates that the first parameter "character" must be a single
character and can't be a string.

I'm guessing there isn't anything to do this other than writing your
own function correct?
Chris

George Bina wrote:
If you can use XSLT 2.0 then you can use a character map. Just add the
following lines to your stylesheet and the tabs will be removed from
output:

<xsl:character-map name="test">
<xsl:output-character character=" " string=""/>
</xsl:character-map>
<xsl:output use-character-maps="test"/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

cmay wrote:
I am having this problem...
Lets say that your source XML is formatted like this:
<somenode>
Here is some text
Here is some more text
</somenode>
>
When to a <xsl:value-of select="somenode" /I want the output to be
free of the tabs that are included in the source XML.
These tabs are not really part of the content, but rather just there
for formatting reasons.
>
I tried doing:
<xsl:value-of select='translate(somenode,"&#x9", "")'/>
But that didn't seem to have an effect.
>
>
Any way to do this?
Aug 2 '06 #12

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

Similar topics

3
by: Greg Jones | last post by:
Hello, This may be a simple question but difficult to search on since the keywords are so generic. Is there a way, in XSLT, to copy an embedded DTD from the source XML to the target XML?...
8
by: David Dorward | last post by:
I'm looking for an XSLT that I can use to transform XHTML 1.0 Strict into HTML 4.01. Does anyone know of a nice prewritten one? -- David Dorward ...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
15
by: Tom Plunket | last post by:
The documentation for dedent says, "Remove any whitespace than can be uniformly removed from the left of every line in `text`", yet I'm finding that it's also modifying the '\t' characters, which...
10
by: Andy Fish | last post by:
hi, I have an XSLT which is producing XML output. many of the nodes in the output tree contain namespace declarations for namespaces that are used in the source document even though they are...
1
by: Nougatti | last post by:
Hi, I am trying to remove part of an xml file using xslt. The output should be an exact copy of the input, but one node should be removed based on an attribute value. for instance: <AAA> ...
6
by: Olagato | last post by:
I need to transform this: <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <url> <loc>http://localhost/index.php/index./Paths-for-the-extreme-player</ loc> </url> <url>...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.