XSL和实体 [英] XSL and entities

查看:142
本文介绍了XSL和实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xsl转换中遇到了问题。

我的xml输入:


--- input.xml ---


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

<!DOCTYPE xc:content [

<!ENTITY%xhtml PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN"

" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

%xhtml;

]>

< xc:xcontent xmlns:xc =" http://www.wolterinkwebdesign.com/xml/xcontent"的xmlns = QUOT; HTTP://www.w3.org/1999/xhtml" module =" news">

< xc:text type =" html">

leuk he jazeker ??é< br />

< / xc:text>

< / xc:xcontent>


----


和一个xsl文件:


- style.xsl ---


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

< xsl:stylesheet version =" 1.0"

xmlns =" http:// www .w3.org / 1999 / xhtml"

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

xmlns:page =" http://www.wolterinkwebdesign.com/xml/page"

xmlns:xc =" http://www.wolterinkwebdesign.com/xml/xcontent">


< xsl:output method =" xml" indent =" yes" />


<! -

!所有html都应保留为html

! - >

< xsl:template match =" * [namespace-uri(。)=''http:// www.w3.org/1999/xhtml'']">

< xsl:copy>

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

< xsl:copy />

< / xsl:for-each>

< xsl: apply-templates select =" ./ node()" />

< / xsl:copy>

< / xsl:template>


< xsl:template match =" / xc:xcontent">

< page:page type =" module">

< p>

< xsl:apply-templates select =" xc:text" />

< / p>

< / page:page>

< / xsl:template>


< / xsl:stylesheet>


---


这里的输出是:


---

< page:page type =" module">

< p>

leuk he jazeker< br />

< / p>

< ; / page:page>


---

但我希望这可以作为输出

---

< page:page type =" module">

< p>

leuk he jazeker ??é< br />

< / p>

< / page:page>

---

怎么可能,为什么是字符:??é去了?

我的编码有问题吗?

注意:我不知道这些文件是否真的编码过ISO-8859-1,但它对我有用。

我的编辑说编码是ISO-8859-1,所以我认为这很好..或者编辑得到了
来自xml prolog的
信息?

解决方案

>切好


好​​吧,我的话题主题并不是一个很好的选择。没有涉及的实体。




他们真的不见了,或者你只是看某个程序中的文件

不理解编码,它们似乎已经消失了你的b $ b发布输出但是这与xslt应该做的不匹配。

那个输出还缺少xhtml的命名空间声明,是不是
真的是你从XSLT获得的输出?


如果你想要iso-8859-1输出add

< xsl:output encoding =" iso-8859-1" />

到您的样式表。


顺便提一句尽管您已经参考了

主题行中的实体,但如果输入所有内容,则输入中没有实体引用(

参数实体引用%xhtml除外)你的角色

直接作为角色数据没有必要引用xhtml dtd

(这可能会对解析速度产生非常明显的影响) ,特别是

,如果你真的每次都在关闭eth w3c网站的dtd)


David


< blockquote>


Tjerk Wolterink写道:

我在xsl转换中遇到了问题。
我的xml输入:

--- input.xml ---

<?xml version =" 1.0" encoding =" ISO-8859-1"?>
<!DOCTYPE xc:content [
^^^^^^^^^^

<! ENTITY%xhtml PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
%xhtml;
]>
< xc:xcontent xmlns:xc =" http://www.wolterinkwebdesign.com/xml/xcontent"


如果DOCTYPE声明中的根元素是xc:content,那么你应该有
,但你有xc:xcontent所以需要更改。

xmlns =" http://www.w3.org/1999/xhtml" module =" news">
< xc:text type =" html">
leuk he jazeker ??é< br />
< / xc:text> ;
< / xc:xcontent>

----
和xsl文件:

- style.xsl ---

<?xml version =" 1.0" encoding =" ISO-8859-1"?>
< xsl:stylesheet version =" 1.0"
xmlns =" http://www.w3.org/1999/xhtml" ;
xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"
xmlns:page =" http://www.wolterinkwebdesign.com/xml/page" ;
xmlns:xc =" http://www.wolterinkwebdesign.com/xml/xcontent">

< xsl:output method =" xml"缩进= QUOT;是" />


你想要什么输出编码?

<! -
!所有html都应该保持html
! - >
< xsl:template match =" * [namespace-uri(。)=''http://www.w3.org/1999/ xhtml'']">
< xsl:copy>
< xsl:for-each select =" @ *">
< xsl:copy /> ;
< / xsl:for-each>
< xsl:apply-templates select =" ./ node()" />
< / xsl:copy>
< / xsl:template>


可以更简单,更高效:


< xsl:template match =" xhtml:*">

< xsl:copy>

< xsl:copy-of select =" @ *" />

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

< / xsl:copy>

< / xsl:template>

其中前缀xhtml绑定到文档中早期的XHTML的名称空间URI




这里的输出是:

---
< page:page type =" module">
< p>
leuk he jazeker< br />
< / p>
< / page:page>

---

但我希望这可以作为输出

---
< page:page type =" module">
< p>
leuk he jazeker ??é< br />
< / p>
< / page:page>
---




你使用什么XSLT处理器,你究竟如何运行

转换?


-


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

I''ve a problem in an xsl transformation.
My xml input:

--- input.xml ---

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xc:content [
<!ENTITY % xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
%xhtml;
]>
<xc:xcontent xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent" xmlns="http://www.w3.org/1999/xhtml" module="news">
<xc:text type="html">
leuk he jazeker ??é<br/>
</xc:text>
</xc:xcontent>

----

And an xsl file:

-- style.xsl ---

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent">

<xsl:output method="xml" indent="yes"/>

<!--
! All html should remain html
!-->
<xsl:template match="*[namespace-uri(.)=''http://www.w3.org/1999/xhtml'']">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates select="./node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="/xc:xcontent">
<page:page type="module">
<p>
<xsl:apply-templates select="xc:text"/>
</p>
</page:page>
</xsl:template>

</xsl:stylesheet>

---

The output here is:

---
<page:page type="module">
<p>
leuk he jazeker<br/>
</p>
</page:page>

---
But i expect this as output
---
<page:page type="module">
<p>
leuk he jazeker ??é<br/>
</p>
</page:page>
---
How can that be, why are the characters: ??é gone??
Is there something wrong with my encoding?
Note: i do''nt know if the files are really encoded in ISO-8859-1, but it did work for me.
My editor says the encoding is ISO-8859-1 so i think that is good.. Or did the editor get that
information from the xml prolog?

解决方案

> cut

Well my topic-subject is not really a good choice. there are not entities involved.



are they really gone or are you just looking at the file in some program
that doesn''t understand the encoding, they appeared to be gone inyour
posted output but that does''nt match what xslt should have done.
That output is also missing a namespace declaration for xhtml, is it
really the output you got from XSLT?

If you want iso-8859-1 output add
<xsl:output encoding="iso-8859-1"/>
to your stylesheet.

Incidentally despite the fact that you have refered to entities in the
subject line there are no entity references in your input (except the
parameter entity reference %xhtml) if you enter all your characters
directlly as character data there''s no need to reference the xhtml dtd
(which might have a very noticable effect on parsing speed, especially
if you really are fetching the dtd off eth w3c site each time)

David




Tjerk Wolterink wrote:

I''ve a problem in an xsl transformation.
My xml input:

--- input.xml ---

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xc:content [ ^^^^^^^^^^
<!ENTITY % xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
%xhtml;
]>
<xc:xcontent xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent"
If the DOCTYPE declaration says the root element is xc:content then you
should have that but you have xc:xcontent so one needs to be changed.
xmlns="http://www.w3.org/1999/xhtml" module="news">
<xc:text type="html">
leuk he jazeker ??é<br/>
</xc:text>
</xc:xcontent>

----

And an xsl file:

-- style.xsl ---

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:xc="http://www.wolterinkwebdesign.com/xml/xcontent">

<xsl:output method="xml" indent="yes"/>
What output encoding do you want?
<!--
! All html should remain html
!-->
<xsl:template match="*[namespace-uri(.)=''http://www.w3.org/1999/xhtml'']">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates select="./node()"/>
</xsl:copy>
</xsl:template>
Could be done easier and more efficient:

<xsl:template match="xhtml:*">
<xsl:copy>
<xsl:copy-of select="@* " />
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

where the prefix xhtml is bound to the namespace URI for XHTML earlier
in the document.

The output here is:

---
<page:page type="module">
<p>
leuk he jazeker<br/>
</p>
</page:page>

---
But i expect this as output
---
<page:page type="module">
<p>
leuk he jazeker ??é<br/>
</p>
</page:page>
---



What XSLT processor are you using, how exactly do you run the
transformation?

--

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


这篇关于XSL和实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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