2017-07-26 9 views
1

希望する.xmlファイルを生成するために、.odsファイル(zipのcontent.xmlファイル)をXSLTで変換しようとしています。XSLTで特定の.ODSセルのコンテンツを取得する方法

XSLTは要素の固定位置を使用してコンテンツを取得しますが、.odsファイルでは空白のフィールドが多く、XSLTでカウントする方法はわかりません。

さらに、これらの空の(空の)セルが保存されているかどうかを調べるために、content.xmlでいくつかの実験を行いました。 content.xml

私のようなものを見つけました:

<table:table-column table:style-name="co1" table:number-columns-repeated="16384" table:default-cell-style-name="ce1"/> 
<table:table-row table:number-rows-repeated="1048576" table:style-name="ro1"> 

.odsファイル内の空のセルまたは値の実際の位置を表す(数学的計算で例えば)何らかの形でこれらの値はありますか?

あなたは

.ods例を、より明確なアイデアを持っているため、私はここに私のドキュメントを共有:

enter image description here

これは私のXSLTファイルです:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fn="http://www.w3.org/2005/xpath-functions" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:espd="urn:com:grow:espd:02.00.00" xmlns:cac="urn:X-test:UBL:Pre- 
award:CommonAggregate" xmlns:cbc="urn:X-test:UBL:Pre-award:CommonBasic" 


<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="office:spreadsheet/table:table"> 
<xsl:variable name="test" select="table:table-row/table:table-cell"/> 
<p><xsl:value-of select="$test/text:p[1]"/></p> 
</xsl:template> 

、出力は次のとおりです。

ブラクburak5 burak6 burak2 burak3 burak4 burak7 burak9 burak8 burak10

質問:適用することによって、細胞からの単一の値を取得する方法

content.xmlの変換? content.xmlに変換を適用することにより、細胞からの単一の値を取得する方法:(どのように到達するためにちょうどD4を細胞例えば?)

答えて

1


.odsファイルのcontent.xmlにおけるXMLデータ(常にtable:名前空間接頭辞)は、この方法でエンコードされています

  • table-celltable-row
  • table-cellの中に含まれているが、空の符号化されていますで示され、スキップする必要がありますが、カウントする必要があります。
  • table-rowのsが
  • table-columns
  • は、例えば特定のセルを取得するには、

だから、冒頭でのみ使用するように見えるnumber-rows-repeated="..."属性によって示され、あまりにも、RLEでエンコードされていますD4 = 4:4、スキップされたものを含むtable-row Sを計数しなければならない。

D4 = 4:4 = Get the fourth `table-row`, add one cell D1, then add number-columns-repeated="2" 

これはGetCellValue例に(2.0および3.0も使用可能)は、いくつかのXSLT-1.0コードある:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fn="http://www.w3.org/2005/xpath-functions" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:espd="urn:com:grow:espd:02.00.00" 
xmlns:cac="urn:X-test:UBL:Pre-award:CommonAggregate" 
xmlns:cbc="urn:X-test:UBL:Pre-award:CommonBasic" exclude-result-prefixes="xs fn office style table text espd cac cbc"> 

<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/> 
<xsl:variable name="str" select="'x:1 y:4'" />    <!-- define some coord system --> 


    <xsl:template match="/office:document-content/office:body/office:spreadsheet/table:table"> 
    Table dimensions: <xsl:call-template name="GetDimensions" /> 
    Value at 5x8: <xsl:call-template name="GetCellValue"> 
     <xsl:with-param name="x" select="5" /> 
     <xsl:with-param name="y" select="8" /> 
    </xsl:call-template> 
    Value at 1x4: <xsl:call-template name="GetCellValue"> <!-- use string defined above --> 
     <xsl:with-param name="x" select="substring-after(substring-before($str,' '),'x:')" /> 
     <xsl:with-param name="y" select="substring-after($str,'y:')" /> 
    </xsl:call-template> 
    </xsl:template> 

    <xsl:template name="GetCellValue"> 
    <xsl:param name="x" /> 
    <xsl:param name="y" /> 
    <xsl:variable name="targetRow" select="table:table-row[sum(preceding-sibling::*/@table:number-rows-repeated) + position() - count(preceding-sibling::*/@table:number-rows-repeated)= $y]" /> 
    <xsl:variable name="targetCell" select="$targetRow/table:table-cell[sum(preceding-sibling::*/@table:number-columns-repeated) + position() - count(preceding-sibling::*/@table:number-columns-repeated) &lt;= $x]" /> 
    <xsl:copy-of select="$targetCell[last()]/text:p/text()" /> 
    </xsl:template> 

    <xsl:template name="GetDimensions"> 
    <xsl:variable name="firstRow" select="table:table-row[1]/table:table-cell" /> 
    <xsl:variable name="firstColumn" select="table:table-row" /> 
    <xsl:variable name="width" select="count($firstRow)+ sum($firstRow/@table:number-columns-repeated) - count($firstRow/@table:number-columns-repeated)" /> 
    <xsl:variable name="height" select="count($firstColumn)+ sum($firstColumn/@table:number-rows-repeated) - count($firstColumn/@table:number-rows-repeated)" /> 
    <xsl:value-of select="concat($width,'x',$height)" /> 
    </xsl:template> 

</xsl:stylesheet> 

出力は次のとおりです。

Table dimensions: 5x12 
Value at 5x8: burak9 
Value at 1x4: burak4 

編集:
xsl:call-templateをカスタムフォーマットの文字列入力で使用するように修正しました。 x:1 y:4

+0

ありがとうございます!私を混乱させるものはほとんどありません。あなたは多くの情報を持った大きなファイルを持っていると想像してください。このアプローチは実現可能ですか?私が選択しなければならないのは、私が言及しなかったもう一つのことは、XSLT 2.0での変換が必要だということです。 – Sojimanatsu

+0

@さとまなつ:はい。大きなファイルでも動作するはずです。したがって、100の固定位置は2つより良好に動作するはずです。それは遅くなりますが、おそらくそれほど遅くはありません。 BTWこのテンプレートはXSLT-2.0と3.0でも動作しますが、番号を変更するだけです;-)。 – zx485

+0

@司丸:ありがとうございます。 – zx485

関連する問題