Trim all innertext/attributes values with XSL
-
Hi, I'm parsing a fixed size flat file document and convert it into XML, but I therefore have output like
<root>
<foo bar=" lulz "> zomg </foo>
<hello> world</hello>
</root>Which I'd like to look like:
<root>
<foo bar="lulz">zomg</foo>
<hello>world</hello>
</root>Is there a way to do this with XSLT? I've tryed a copy/copy-of and normalize-space, but it doesn't give me the output I'd want. This is driving me insane. Thanks!
-
Hi, I'm parsing a fixed size flat file document and convert it into XML, but I therefore have output like
<root>
<foo bar=" lulz "> zomg </foo>
<hello> world</hello>
</root>Which I'd like to look like:
<root>
<foo bar="lulz">zomg</foo>
<hello>world</hello>
</root>Is there a way to do this with XSLT? I've tryed a copy/copy-of and normalize-space, but it doesn't give me the output I'd want. This is driving me insane. Thanks!
-
Tony_P wrote:
I'm parsing a fixed size flat file document and convert it into XML
Why don't you trim the spaces during the parsing/processing of the flat file?
That'd be indeed nice but it's document generated by webMethods, I can't do that.
-
That'd be indeed nice but it's document generated by webMethods, I can't do that.
-
Hi, I'm parsing a fixed size flat file document and convert it into XML, but I therefore have output like
<root>
<foo bar=" lulz "> zomg </foo>
<hello> world</hello>
</root>Which I'd like to look like:
<root>
<foo bar="lulz">zomg</foo>
<hello>world</hello>
</root>Is there a way to do this with XSLT? I've tryed a copy/copy-of and normalize-space, but it doesn't give me the output I'd want. This is driving me insane. Thanks!
You can use
translate
, a XPath function, with an empty replace string.translate($data, " ", "")
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
You can use
translate
, a XPath function, with an empty replace string.translate($data, " ", "")
"We make a living by what we get, we make a life by what we give." --Winston Churchill
This cannot work as you need to know the structure of the document to apply translate. I don't think this is possible, I've been searching the whole internet, and nothing came up. XSLT is such a stupid standard.
-
This cannot work as you need to know the structure of the document to apply translate. I don't think this is possible, I've been searching the whole internet, and nothing came up. XSLT is such a stupid standard.
-
This cannot work as you need to know the structure of the document to apply translate. I don't think this is possible, I've been searching the whole internet, and nothing came up. XSLT is such a stupid standard.
If you are using .NET, have you considered using Script Blocks using
msxsl:script
to create your own XSLT trimming function? An even better solution is to useXsltArgumentList
. Also, what isnormalize-space
not doing to fit your needs?"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Friday, February 13, 2009 11:56 AM