在属性值中维护一个大字符 [英] Maintaining a Great-than Character in an Attribute Value

查看:46
本文介绍了在属性值中维护一个大字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换以下xml文件

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

< ;?xml version =" 1.0" encoding =" ISO-8859-1"?>

< a>

< b attrib =" if 3 2">

< / b>


< b attrib =" 3 1">

< / b>

< / a>


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

到这个xml文件中

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

<? xml version =" 1.0" encoding =" ISO-8859-1">

< a>

< b attrib =" 3 2">

< / b>


< b attrib =" 3 1">

< / b>

< / a>


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


即我想删除if从价值开始的字符

属性attrib


我正在使用样式表...

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

<?xml version =" 1.0" encoding =" ISO-8859-1"?>

< xsl:stylesheet xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"

version =" 1.0">

< xsl:template match =" node()| @ *">

< xsl:copy>

< xsl:apply-templates select =" @ * | node()" />

< / xsl:copy>

< / xsl:template>


< xsl:template match =" @attrib [starts-with(。,''if'')]">

< xsl:attribute name =" attrib">

< xsl:value-of select =" substring-after(。,''if'')" />

< / xsl:attribute> ;

< / xsl:template>

< / xsl:stylesheet>


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

带有Xalan Version Xalan Java 2.4.1的
,但我得到以下输出

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

<?xml version =" 1.0" encoding =" ISO-8859-1"?>

< a>

< b attrib =" 3& gt; 2">

< / b>


< b attrib =" 3& gt; 1">

< / b>

< / a>


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


其中大于号字符更改为& gt; 。


我还需要在输出中输入单个字符。


在XSLT中是否有任何方法可以保持大于和少于

字符和<转换时的属性值而不是

有& gt;和& lt; ?


如果在XSLT中无法实现这一目标,那么推荐的

方法是什么?


任何帮助都非常感谢,


问候,


公制

I want to transform the following xml file
------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<a>
<b attrib="if 3 2">
</b>

<b attrib="3 1">
</b>
</a>

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

into this xml file
------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<a>
<b attrib="3 2">
</b>

<b attrib="3 1">
</b>
</a>

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

i.e. I want to remove the "if" character from the start of the value of
the attribute "attrib"

I am using the style sheet...
------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="node( ) | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node( )"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@attrib[starts-with(., ''if '')]">
<xsl:attribute name="attrib">
<xsl:value-of select="substring-after(., ''if '')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

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

with "Xalan Version Xalan Java 2.4.1", but I get the following output
------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<a>
<b attrib="3 &gt; 2">
</b>

<b attrib="3 &gt; 1">
</b>
</a>

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

where the greater-than character is changed to &gt; .

I need to have the single character in the output also.

Is there any way in XSLT of keeping the greater-than and less-than
characters and < in attribute values when you transform instead of
having &gt; and &lt; ?

If there is no way to achieve this in XSLT, what would be the
recommended method for achieving this?

Any help\pointers greatly appreciated,

Regards,

Metric

推荐答案



go************@yahoo.co.uk 写道:



go************@yahoo.co.uk wrote:


withXalan Version Xalan Java 2.4.1",但我得到以下输出
with "Xalan Version Xalan Java 2.4.1", but I get the following output


< b attrib =" 3& gt; 2英寸;>
<b attrib="3 &gt; 2">


其中大于号字符更改为& gt; 。


我还需要输出中的单个字符。
where the greater-than character is changed to &gt; .

I need to have the single character in the output also.



为什么,任何XML解析器/工具都应该正确地解除& gt;实体

引用为''>''字符?


如果你想要''>''那么我想你需要自己编写序列化器

序列化XSLT转换的结果树。

-


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



去************ @ yahoo .co.uk 写道:

go************@yahoo.co.uk wrote:

其中大于号字符更改为& gt; 。

我还需要输出中的单个字符。
where the greater-than character is changed to &gt; .
I need to have the single character in the output also.



然后停止需要。
http://www.w3.org/TR/2004/REC-xml-20040204/#syntax

角色">"可以编码为& gt;你遇到它的地方。

如果你的XML消费应用程序没有认识到这是一个错误。你应该集中精力解决这个问题,而不是解决它的问题。否则会产生这些错误并构建一个非稳健的

系统。

Then stop needing that.
http://www.w3.org/TR/2004/REC-xml-20040204/#syntax
The character ">" MAY be encoded as &gt; where you''re encountering it.
So it''s an error if your XML-consuming application doesn''t recognise
that. You should concentrate on fixing that, not working around its
errors. Otherwise these errors build up and you build a non-robust
system.


XSLT中是否有任何方法可以保留大于和小于
Is there any way in XSLT of keeping the greater-than and less-than

字符和<转换时的属性值而不是

有& gt;和& lt; ?
characters and < in attribute values when you transform instead of
having &gt; and &lt; ?



不在XSLT中,不是。编写自己的序列化程序,或者(更简单)编写

a基于文本处理的后处理器。


更好的答案:不要修复什么不能打破。如果您的问题是某些

下游工具关心这种差异,请修复该工具。


-

()ASCII功能区活动| Joe Kesselman

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

Not in XSLT by itself, no. Write your own serializer, or (simpler) write
a text-processing-based postprocessor.

Better answer: Don''t fix what ain''t broke. If your problem is that some
downstream tool cares about this difference, fix that tool.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


这篇关于在属性值中维护一个大字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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