解释XML和XSL文件中的HTML标记

时间:2014-01-08 18:02:11

标签: html xml xslt

我使用的是AngularJS,XML,XSL和HTML5。

这是我的XML:

 <?xml version="1.0" encoding="UTF-8"?>
 <?xml-stylesheet type="text/xsl" href="index.xsl"?>
 <methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generalMethod_Type.xsd">
    <persona>
        <creation_file>
            <creator_name>My name is John</creator_name>
            <file_name>file_name0</file_name>
            <date_creation>2006-05-04T18:13:51.0</date_creation>
        </creation_file>
     </persona>

我希望将“JOHN”改为斜体(带有<i> HTML标记),以便在浏览器中显示如下:

What's your name? My name is *John*

这是index.xsl的简化部分,我在其中调用<creator_name>的值:

<div>
What's your name? <xsl:value-of select="//creator_name"/>
</div>

我想以下列方式将<i>标记放在XML中:

 <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="index.xsl"?>
<methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="generalMethod_Type.xsd">
    <persona>
        <creation_file>
            <creator_name>My name is <i>John</i></creator_name>
            <file_name>file_name0</file_name>
            <date_creation>2006-05-04T18:13:51.0</date_creation>
        </creation_file>
     </persona>

但不允许这样做,因为<creator_name>没有<i>个孩子,浏览器也不会解释它。

您对此问题有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你应该使用CSS。

<强> INDEX.XML

<?xml version="1.0"?>
<?xml-stylesheet href="index.css"?>
<title>This is the <i>TITLE</i></title>

<强> index.css

i {
  font-style: italic;
}