从XSLT的输出中删除源XML中的选项卡 [英] Removing Tabs from source XML in output from XSLT

查看:70
本文介绍了从XSLT的输出中删除源XML中的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个问题...

让我们说你的源XML格式如下:

< somenode>

这里有一些文字

这里有更多的文字

< / somenode>


什么时候到< xsl:value -of select =" somenode" /我希望输出为

,不包含源XML中包含的选项卡。

这些选项卡实际上不是内容的一部分,而是仅仅是

出于格式化原因。

我尝试过:

< xsl:value-of select =''translate(somenode, "&#x9","")''/>

但这似乎没有效果。

任何方法这个?div / =

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?

推荐答案

这些标签实际上不是内容的一部分,而是只有
These tabs are not really part of the content, but rather just there

出于格式原因。
for formatting reasons.



嗯,最好的答案不是将它们用于格式化,而是用于人类想要的人类的b $ b格式读取数据。

然而,假设你坚持使用它们......

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","")''/>
<xsl:value-of select=''translate(somenode,"&#x9", "")''/>



不,那不行; translate绝对是一个替换操作,并且
不能用来删除字符。


如果你知道只有一个标签,你可以使用

concat(substring-before(somenode,"&#x9"),

substring-after(somenode,"&#x9") )

如果可能有多个标签,你需要重复这一点,直到所有标签

都被处理掉 - 这在XSLT 1.0中意味着写一个递归的

命名模板并通过call-template调用它。 (XSLT 2.0有一个稍微优雅的写入和调用函数的语法。)我是

确定在XSLT常见问题中有这种方法的例子,或者很多

体面的XSLT教程。


或者你可以调用非XSLT扩展函数,如果你的处理器支持那么。


-

()ASCII Ribbon Campaign | Joe Kesselman

/ \标记HTML电子邮件! |系统架构和动态诗歌

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




cmay写道:



cmay wrote:


我尝试过:

< xsl:value-of select =''translate(somenode,"&#x9","")''/>

但这似乎没有效果。
I tried doing:
<xsl:value-of select=''translate(somenode,"&#x9", "")''/>
But that didn''t seem to have an effect.



该标签字符的代码编号为9,字符参考需要

以分号结尾所以你需要

< xsl:value-of select =''translate(somenode,"","")''/>


那应该在我的看来,与Joe说的相反,翻译

< http://www.w3.org/TR/xpath#function-translateindeed删除

字符在第二个中找到在第三个参数字符串中没有

对应位置的参数字符串。


-


Martin Honnen
http://JavaScript.FAQTs.com/


对丢失的分号有好处,是的,删除应该有效;我b $ b $ m $ b错误地记错了。 (叹息。累了不要打字。)


-

()ASCII Ribbon Campaign | Joe Kesselman

/ \标记HTML电子邮件! |系统架构和动态诗歌
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


这篇关于从XSLT的输出中删除源XML中的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆