XML中的html下标

扎克·托马斯(Zach Thomas)

我尝试使用<sub> </ sub>标记在线打开我的xml文件下标的一部分时,但是当我在Internet Explorer中打开xml文件时出现问题(没有说什么错误只是没有在IE中看起来正确)。我认为这是因为xml正在读取<sub>作为另一个子元素,但是<sub>仅用于告诉hmtl在线制作xml文件下标的某些部分。有什么改变的想法吗?我还使用xsl将xml转换为html以进行在线发布。下面的代码

XML档案:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="ALDformat.xsl"?>

<ALD_data>
<Element Title = "lithium">
<Element>lithium </Element>
<Compound Subtitle = "Li<sub>2</sub>CO<sub>3</sub>">
<Compound> Li<sub>2</sub>CO<sub>3</sub> </Compound>
<Precursor>
<precursor1> Li(thd) </precursor1>
<precursor2> O<sub>3</sub> </precursor2>
<Ref2> Putkonen2009 </Ref2>
</Precursor>
</Compound>
<Compound Subtitle = "Li<sub>2</sub>O(LiOH)">
<Compound> Li<sub>2</sub>O(LiOH) </Compound>
<Precursor>
<precursor1> Li(O<sup>t</sup>Bu) </precursor1>
<precursor2> H<sub>2</sub>O </precursor2>
<Ref2> Aaltonen2010 </Ref2>
</Precursor>
</Compound>
</Element>
</ALD_data>

XSL文件:

<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">

<h1>ALD literature XML database</h1>
<p>Last update: 6 January 2016</p>

<xsl:for-each select="ALDdata/Element">
  <div style="background-color:teal;color:white;padding:4px">
    <span style="font-weight:bold"> Element: <xsl:value-of select="Element"/> </span>
  </div>
  <xsl:for-each select="Compound">
    <div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
      <p>
      <span> Compound: <xsl:value-of select="Compound"/> </span>
      </p>
    </div>
    <xsl:for-each select="Precursor">
      <div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
        <p>
        Precursor 1: <xsl:value-of select="precursor1"/> <br/>
        Precursor 2: <xsl:value-of select="precursor2"/>
        </p>
      Post-2005 review paper references
      <ol>
      <xsl:for-each select="Ref2">
          <li><xsl:value-of select="."/></li>
      </xsl:for-each>
      </ol>
      </div>
    </xsl:for-each>
  </xsl:for-each>
</xsl:for-each>
</body>
</html>
丹尼尔·海利(Daniel Haley)

为了处理您的subsup元素,您必须使用xsl:apply-templates来代替xsl:value-of包含sub的元素sup

我认为您不能将文字结果元素用作样式表并添加模板。

也许尝试像这样的事情...

XML输入(注:我不得不删除该化合物的价值/ @字幕属性,因为它们没有很好形成。)

<?xml-stylesheet type="text/xsl" href="ALDformat.xsl"?>
<ALD_data>
    <Element Title = "lithium">
        <Element>lithium </Element>
        <Compound Subtitle = "">
            <Compound> Li<sub>2</sub>CO<sub>3</sub> </Compound>
            <Precursor>
                <precursor1> Li(thd) </precursor1>
                <precursor2> O<sub>3</sub> </precursor2>
                <Ref2> Putkonen2009 </Ref2>
            </Precursor>
        </Compound>
        <Compound Subtitle = "">
            <Compound> Li<sub>2</sub>O(LiOH) </Compound>
            <Precursor>
                <precursor1> Li(O<sup>t</sup>Bu) </precursor1>
                <precursor2> H<sub>2</sub>O </precursor2>
                <Ref2> Aaltonen2010 </Ref2>
            </Precursor>
        </Compound>
    </Element>
</ALD_data>

XSLT 1.0(ALDformat.xsl)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/*">
    <html>
      <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
        <h1>ALD literature XML database</h1>
        <p>Last update: 6 January 2016</p>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Element[@Title]">
    <div style="background-color:teal;color:white;padding:4px">
      <span style="font-weight:bold"> Element: <xsl:apply-templates select="Element"/> </span>
    </div>
    <xsl:apply-templates select="Compound"/>
  </xsl:template>

  <xsl:template match="Compound[@Subtitle]">
    <div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
      <p>
        <span> Compound: <xsl:apply-templates select="Compound"/> </span>
      </p>
    </div>
    <xsl:apply-templates select="Precursor"/>      
  </xsl:template>

  <xsl:template match="Precursor">
    <div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
      <p>
        Precursor 1: <xsl:apply-templates select="precursor1"/> <br/>
        Precursor 2: <xsl:apply-templates select="precursor2"/>
      </p>
      Post-2005 review paper references
      <ol>
        <xsl:apply-templates select="Ref2"/>
      </ol>
    </div>      
  </xsl:template>

  <xsl:template match="sub|sup">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="Ref2">
    <li><xsl:apply-templates/></li>
  </xsl:template>

</xsl:stylesheet>

输出

<html>
   <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
      <h1>ALD literature XML database</h1>
      <p>Last update: 6 January 2016</p>
      <div style="background-color:teal;color:white;padding:4px"><span style="font-weight:bold"> Element: lithium </span></div>
      <div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
         <p><span> Compound:  Li<sub>2</sub>CO<sub>3</sub></span></p>
      </div>
      <div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
         <p>
            Precursor 1:  Li(thd) <br>
            Precursor 2:  O<sub>3</sub></p>
         Post-2005 review paper references
         
         <ol>
            <li> Putkonen2009 </li>
         </ol>
      </div>
      <div style="background-color:lightgrey;margin-left:20px;margin-bottom:1em;font-size:10pt">
         <p><span> Compound:  Li<sub>2</sub>O(LiOH) </span></p>
      </div>
      <div style="margin-left:30px;margin-bottom:1em;font-size:10pt">
         <p>
            Precursor 1:  Li(O<sup>t</sup>Bu) <br>
            Precursor 2:  H<sub>2</sub>O 
         </p>
         Post-2005 review paper references
         
         <ol>
            <li> Aaltonen2010 </li>
         </ol>
      </div>
   </body>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章