XLT 不解析 Saxon 中的数据 [英] XLT does not parse the data in Saxon

查看:48
本文介绍了XLT 不解析 Saxon 中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


关于我的目标的简短说明.我想用 Saxon 解析一个 xlm 文件,最后得到一个带有代码的文本文件.像这样的东西:function1(){
a+a;}
function2(){
b+b;}
function3(){
c+c;}
我的想法是使用 <apply> 模板标签创建此类代码,以便对于每个面向 标签的文本文件,将使用必要的方法填充位于 标签中.例如,对于 <tr> 的每个第一个子项都是一个 function1().以下是错误:


Short about my aim. I want to parse a xlm file with Saxon and at the end get a text file with code. Something like this: function1(){
a+a;}
function2(){
b+b;}
function3(){
c+c;}
My Idea is to create Such code using <apply> template tag so that for each facing a <tr> tag, a text file would be fullfiled with necessary methods that are in <td> tags. For example for each first child of <tr> is a function1(). Here are the errors:

    Warning
      XTDE0540: Ambiguous rule match for /html/body[1]/table[1]
    Matches both
      "document-node()/element(Q{http://www.w3.org/1999/xhtml}html)/element(Q{http://www.w3.org/1999/xhtml}body)/element(Q{http://www.w3.org/1999/xhtml}table)" on line 71 of file:/C:/Users/fleonov/Desktop/test_for_thomas/Var_05_02/transfer_html.xsl
    and "document-node()/element(Q{http://www.w3.org/1999/xhtml}html)/element(Q{http://www.w3.org/1999/xhtml}body)/element(Q{http://www.w3.org/1999/xhtml}table)" on line 21 of file:/C:/Users/fleonov/Desktop/test_for_thomas/Var_05_02/transfer_html.xsl
    <?xml version="1.0" encoding="UTF-8"?>

          Use_Cases
          <br xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:xhtml="http://www.w3.org/1999/xhtml"/><p 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
 xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:xhtml="http://www.w3.org/1999/xhtml">function1()<br/>

    {<br/><br/>function1()<br/>

但每次我看到这样的东西(在不同的变化).这是我的 xlt 和 xml 代码:

But each time I see such thing(in different variations). Here is mine xlt and xml code:

<xsl:template  match="/html/body/table" >
<xsl:variable name="main_file" select="concat(lower-case(../h1),'_stimuli')"/>
<xsl:result-document href="{$main_file}.h" method="text">`
{

<xsl:apply-templates select="/html/body/table" />  //I put apply template here because it is not 
                                                      possible to use 
                                                      <template> inside a <result-document>





    </xsl:result-document>
</xsl:template>



<xsl:template  match="/html/body/table" name="code">

    <xsl:apply-templates select="/html/body/table/tr" />   

</xsl:template>

 <xsl:template  match="/html/body/table/tr" >
      <xsl:apply-templates select="child::td[2]" />
      <xsl:apply-templates select="child::td[3]" />
      <xsl:apply-templates select="child::td[4]" />
 </xsl:template>

<xsl:template match="child::td[2]">
    <br></br>
    <p>function1()<br></br>
    {<br></br>   
<xsl:value-of select="." /><br></br>
    }<br></br>
</p>
</xsl:template> 


<xsl:template match="child::td[3]"><br></br>
<p>function2()<br></br>
{<br></br>
<xsl:value-of select="." /><br></br>
}<br></br>
</p>
</xsl:template> 


<xsl:template match="child::td[4]"><br></br>
<p>function3()<br></br>
{<br></br>
    <br></br>
    <xsl:value-of select="." /><br></br>

}<br></br>
</p>
</xsl:template> 
</xsl:stylesheet>


Here is mine html that I parse.

     <body>
      <h1>Use_Cases</h1>
      <table border="1">
         <tr>
            <td>file_name</td>
            <td>function1()</td>
            <td>function2()</td>
            <td>function3()</td>
            <td>function4()</td>
            <td></td>
         </tr>
         <tr>
            <td>test</td>
            <td>a+a;</td>
            <td>b+b;</td>
            <td>c+c;</td>
            <td>d+d;</td>
            <td></td>
         </tr>


      </table>
   </body>
</html>

提前致谢

推荐答案

如果您知道要处理表格的某些单元格那应该很容易:

If you know you want to process certain cells of a table that it should be easy:

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

  <xsl:template match="/">
    <xsl:apply-templates select="html/body/table/tr[1]/td[position() > 1 and position() &lt; 6]"/>
  </xsl:template>

  <xsl:template match="td">
      <xsl:param name="pos" select="position()"/>
      <xsl:value-of select="., '{', ../following-sibling::tr[1]/td[$pos + 1], '}'" separator="&#10;"/>
      <xsl:text>&#10;</xsl:text>
  </xsl:template>

https://xsltfiddle.liberty-development.net/bwe3c5/1.这会创建纯文本,我不确定为什么您的示例尝试使用仅适合 HTML 输出的 br 元素.

https://xsltfiddle.liberty-development.net/bwe3c5/1. This creates plain text, I am not sure why your example tried to use br elements which would only fit into HTML output.

这篇关于XLT 不解析 Saxon 中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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