Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

xslt - XLT does not parse the data in Saxon


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/>

The command line output

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>

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. This creates plain text, I am not sure why your example tried to use br elements which would only fit into HTML output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...