如何才能使属性值不被转换为&到'或& amp;到&或& lt;到> ? [英] How can I get attribute values to not get converted from ' to ' or & to & or < to > ?

查看:188
本文介绍了如何才能使属性值不被转换为&到'或& amp;到&或& lt;到> ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的思绪疯了。我已经尝试了所有我能想到的东西

no

avail。

我尝试过禁用输出转义。

我试图想出一种将属性数据封装在CDATA

元素中的方法。这没有解析。


这是我的问题:


如何让属性值不被转换为& an;到''

或& amp;到&或& lt;到> ?

好​​像我拿一个xsl:value-of属性然后输出



值到另一个xml中得到'转换了。


问题是我将这些东西导入数据库我需要保持

所有

那些&安培;者;和其他的逃避..


此外,有没有办法做这样的事情

<![CDATA [

< xsl:value-of select =" @ CATEGORY" />

]]>


这个问题是它给了我

< xsl:value-of选择= QUOT; @ CATEGORY" />


我想要的地方

男士服装


感谢任何帮助将不胜感激...

这是我的源xml,XSL和outfile:


源XML:


< ;导入>

< CAT>

< row CATEGORY =" Men& s Clothing" />

< / CAT>

< / import>


XSL:

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

version =" 1.0">


< xsl:output indent =" yes"方法= QUOT; XML" />

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


< xsl:template name =" frank_data" ;>


< xsl:param name =" id" />

< xsl:element name =" frankgroup">

< xsl:attribute name =" identifier">< xsl:value -of select =" $ id"

/>< / xsl:attribute>

< / xsl:element>


< / xsl:template>


< xsl:template match =" /">


< ; xsl:element name =" import">

< xsl:apply-templates />

< / xsl:element>


< / xsl:template>


< xsl:template match =" CAT">

< xsl :for-each select =" *">

< xsl:call-template name =" frank_data">

< xsl:with- param name =" id"选择= QUOT; @ CATEGORY" />

< / xsl:call-template>

< / xsl:for-each>

< / xsl:模板>

< / xsl:stylesheet>

输出:


< import>

< frankgroup

id =" Men's Clothing" />

< / import>

Hi, my mind is going crazy. I have tried everything I can think of to
no
avail.
I have tried Disable Output Escaping.
I tried to think of a way of enclosing the attribute data in a CDATA
element. That did not parse.

Here is my question:

How can I get attribute values to not get converted from &apos; to ''
or &amp; to & or &lt; to > ?
It seems like if I take the xsl:value-of an attribute and then output
that
value into another xml it get''s converted.

The problem is I am importing this stuff into a DB and I need to keep
all
those &apos; and other escapings..

Also, is there a way to do something like this
<![CDATA[
<xsl:value-of select="@CATEGORY" />
]]>

The problem with this is it gives me
<xsl:value-of select="@CATEGORY" />

where I want
Men&apos;s Clothing

Thanks any help would be appreciated...
Here is my source xml, XSL, and outfile:

Source XML:

<import>
<CAT>
<row CATEGORY="Men&apos;s Clothing" />
</CAT>
</import>

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

<xsl:output indent="yes" method="xml" />
<xsl:strip-space elements="*"/>

<xsl:template name="frank_data">

<xsl:param name="id" />
<xsl:element name="frankgroup">
<xsl:attribute name="identifier"><xsl:value-of select="$id"
/></xsl:attribute>
</xsl:element>

</xsl:template>

<xsl:template match="/">

<xsl:element name="import">
<xsl:apply-templates />
</xsl:element>

</xsl:template>

<xsl:template match="CAT">
<xsl:for-each select="*">
<xsl:call-template name="frank_data">
<xsl:with-param name="id" select="@CATEGORY" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:

<import>
<frankgroup
id="Men''s Clothing" />
</import>

推荐答案

id"

/>< / xsl:attribute>

< / xsl:element>


< / xsl:template>


< xsl:template match =" /">


< xsl:element name =" import">

< xsl:apply-templates />

< / xsl:element>


< / xsl:template>


< xsl:template match =" CAT">

< xsl:for-each select =" *">

< xsl:call-template name =" frank_data">

< xsl:with-param name =" id"选择= QUOT; @ CATEGORY" />

< / xsl:call-template>

< / xsl:for-each>

< / xsl:模板>

< / xsl:stylesheet>

输出:


< import>

< frankgroup

id =" Men's Clothing" />

< / import>

id"
/></xsl:attribute>
</xsl:element>

</xsl:template>

<xsl:template match="/">

<xsl:element name="import">
<xsl:apply-templates />
</xsl:element>

</xsl:template>

<xsl:template match="CAT">
<xsl:for-each select="*">
<xsl:call-template name="frank_data">
<xsl:with-param name="id" select="@CATEGORY" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:

<import>
<frankgroup
id="Men''s Clothing" />
</import>



我该怎么办?得到的属性值不能从&到'
或& amp;到&或& lt;到> ?


整点关于& lt;是否与>相同(不是

总是在元素内容中如果前两个字符是]]但是在

属性值中它们总是意味着相同的东西。

如果你去

< foo bar ="& gt;" />< foo bar =">" />然后XSLT会看到来自

这两种形式,它可能会在输出中使用任何一种形式。它无法知道使用哪种形式,而不是知道其他形式的其他形式。

使用或来包围属性值。

问题是我将这些东西导入数据库并且我需要保留所有这些&和其他转义..
How can I get attribute values to not get converted from &apos; to ''
or &amp; to & or &lt; to > ?
The whole point about &lt; is that it means the same thing as > (not
always in element content if the preceding two characters were ]] but in
attribute values they always mean the same thing.
If you go
<foo bar="&gt;"/><foo bar=">"/> Then XSLT will see identical input from
the two forms, and it may use either form on output. It has no way of
knowing which form was used, any more than it has of knowing whther yiou
used " or '' to surround the attribute value.
The problem is I am importing this stuff into a DB and I need to keep
all those &apos; and other escapings..




如果那个导入机制不知道XML约定所以打破了

XML引用语法它们你会有使用

xslt的文本输出方法并写出你想要的文字标签,而不是允许你使用元数据线化你的元素树。但是你失去了大部分日e />
xslt这样做的好处。


所以

< xsl:output method =" text" />

....


< xsl:template match =" xyz">

& lt; foo bar ="< xsl:value-of select =" @ CATEGORY" />" .... /& gt;

....


另外,有没有办法做这样的事情

<![CDATA [

< xsl:value-of select =" @ CATEGORY" />

]]>

嗯,你可以做到这一点,正如你所观察到的那样,然后

< xsl:value -o

被视为字符数据而非元素标记。

这个问题是它给了我

< xsl:value-of选择= QUOT; @ CATEGORY" />

我想要的地方

男士服装


如上所述如果你的意思是你有一个输入字符串

男士服装

你需要它出来

男装  />
而不是

男士服装

然后基本上你不能使用XSLT,因为XML解析器会报告这些

两件事情一样。因此,XSLT无法保留差异。

David



If that import mechanism is not aware of XML conventions so is broken by
XML quoting syntax they you will have to use the text output method of
xslt and write out the literal tags that you want rather than allowing
XSLT to linearise an element tree for you. But you lose most of the
benefits of xslt doing that.

so
<xsl:output method="text"/>
....

<xsl:template match="xyz">
&lt;foo bar="<xsl:value-of select="@CATEGORY"/>" ..../&gt;
....

Also, is there a way to do something like this
<![CDATA[
<xsl:value-of select="@CATEGORY" />
]]>
Well you can do exactly that, as you observe, but then the
<xsl:value-o
is taken as character data not element markup.
The problem with this is it gives me
<xsl:value-of select="@CATEGORY" />
where I want
Men&apos;s Clothing

As I say above If you mean that you had an input string of
Men&apos;s Clothing
and you need it to come out as
Men&apos;s Clothing
and not as
Men''s Clothing
then basically you can''t use XSLT as the XML parser will report these
two things as the same. So there is no way XSLT can preserve the difference.
David


嗯,如果你想让每一个人都出来怎么办? as

&然后呢?

我的意思是实际上我不在乎它是否以''或'&'来表示


我只想让它出来as&

Hmm, whell what if you want everythign to come out as
&apos; then?
I mean actually I don''t care if it comes in as '' or &apos;

I just want it to come out as &apos;


这篇关于如何才能使属性值不被转换为&amp;到'或&amp; amp;到&amp;或&amp; lt;到&gt; ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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