XML / XSLT 中的 HTML 标记

发布于 2024-12-21 00:56:12 字数 682 浏览 1 评论 0原文

生成 XML 的脚本的一部分,该 XML 由 XSLT 摄取并输出到 HTML 网页。

use XML::Writer ;
$writer->emptyTag('Row' , 'text' => $text  ) ;      

效果很好,但现在我想在其中放置一些 HTML 标记...而不是:

$text = "Line of text." ;

我需要:

$text = qq |<span class="blah">Line of text.</span>| ;

尝试在字符串中更改

< 

&lt; 

> 

to

&gt; 

但不起作用...

(更新:回复此处的评论...当我说它“不起作用”时,具体来说,尝试传递 HTML 标记是不成功的,因为标记被显示而不是被处理。换句话说,标签没有被应用,它们只是作为一部分显示。 。

AC)谢谢 全部。我正在学习...

Part of a script that generates XML that is ingested by XSLT and spit out to an HTML web page.

use XML::Writer ;
$writer->emptyTag('Row' , 'text' => $text  ) ;      

Works great, but now I want to put some HTML markup in there... Instead of:

$text = "Line of text." ;

I need:

$text = qq |<span class="blah">Line of text.</span>| ;

Tried changing

< 

to

< 

and

> 

to

> 

in the string but didn't work...

(UPDATE: Responding to a comment here... When I said it "didn't work", specifically, the attempt to pass through HTML markup was unsuccessful, because the markup was displayed instead of being processed. In other words, the tags weren't applied, they just showed up as part of the text. AC)

Thanks all. I'm learning...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倦话 2024-12-28 00:56:13

emptyTag 调用按预期工作,但看起来 XML::Writer 不会尝试为您提供智能,并确定您传递的数据是否会导致格式错误的 XML。

来自 https://metacpan.org/pod/XML::Writer 的文档

emptyTag($name [, $aname1 => $value1, ...])

向 XML 文档添加空标记。元素后面的任何参数 

名称假定为属性的名称/值对(有关详细信息,请参阅 startTag()):

: span class="blah">文本行。 因此,您将执行如下操作:

use XML::Writer;

my $writer = new XML::Writer;

$writer->startTag('span',class=>'blah');
$writer->characters('Line of text.');
$writer->endTag();

The emptyTag call is working as expected, but it looks like XML::Writer is not going to try and be smart for you and figure out if you are passing data that results in badly-formed XML.

From the docs at https://metacpan.org/pod/XML::Writer

emptyTag($name [, $aname1 => $value1, ...])

Add an empty tag to an XML document. Any arguments after the element 

name are assumed to be name/value pairs for attributes (see startTag() for details):

So, to get the XML <span class="blah">Line of text.</span> as a result, you would do something like this:

use XML::Writer;

my $writer = new XML::Writer;

$writer->startTag('span',class=>'blah');
$writer->characters('Line of text.');
$writer->endTag();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文