如何在for-each下访问变量结构以在XSLT中创建Excel工作表

问题描述 投票:0回答:1

我的输入像:

<item id="CON_1985_14">
   <prv id="p1">
      <no>1</no>
      <text>This &quot;May&quot; take some moment, you &quot;shall&quot; not go there.</text>
      <text>This is ok.</text>
   </prv>
</item>

需要在引用值的基础上创建一个Excel表。

=========================
A                 B
=========================
May           CON_1985_14
shall         CON_1985_14
=========================

创建XSLT以生成excel输出,如:

<Worksheet ss:Name="R6">
   <Table>
      <Row>
         <Cell>
            <Data ss:Type="String">
               <xsl:text>A</xsl:text>
            </Data>
         </Cell>
         <Cell>
            <Data ss:Type="String">
               <xsl:text>B</xsl:text>
            </Data>
         </Cell>
      </Row>
      <xsl:for-each select="$path">
         <xsl:for-each select="descendant::prv//descendant::text">
            <xsl:variable name="STRUCTUREONBASISOFTOKENS" as="node()">
               <Report>
                  <dd>
                     <xsl:for-each select="tokenize(normalize-space(.), '(&quot;|&#x201C;)')">
                        <xsl:if test="(position() gt 1) and (position() mod 2 = 0)">
                           <xsl:value-of select="normalize-space(.)"/>
                           <xsl:if test="position() ne (last() - 1)">
                              <xsl:text>, </xsl:text>
                           </xsl:if>
                        </xsl:if>
                     </xsl:for-each>
                  </dd>
                  <LID>
                     <xsl:value-of select="/item/@id"/>
                  </LID>
               </Report>
            </xsl:variable>

            <xsl:for-each select="tokenize($STRUCTUREONBASISOFTOKENS/Report/dd, ',')">
               <Row>
                  <Cell>
                     <Data ss:Type="String">
                        <xsl:value-of select="normalize-space(.)"/>
                     </Data>
                  </Cell>
                  <Cell>
                     <Data ss:Type="String">
                        <xsl:value-of select="$STRUCTUREONBASISOFTOKENS/Report/LID"/>
                     </Data>
                  </Cell>
               </Row>
            </xsl:for-each>
         </xsl:for-each>
      </xsl:for-each>
   </Table>
</Worksheet>

在for-each内部创建的变量,其输出显示在消息中,例如:

<Report xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:LxNx="http://www.LXNX.com"
   xmlns="urn:schemas-microsoft-com:office:spreadsheet"
   xmlns:dict="http://www.lexis-nexis.com/glp/dict" xmlns:ci="http://www.lexis-nexis.com/ci"
   xmlns:o="urn:schemas-microsoft-com:office:office"
   xmlns:x="urn:schemas-microsoft-com:office:excel"
   xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
   <dd>May, shall</dd>
   <LID>CON_1985_14</LID>
</Report>

现在嵌套的for-each,就在变量定义的下面,试图从变量结构中获取值以生成ROW,但没有成功。无法通过xpath从变量获取值以生成行。此语法“”表示collection()路径。

为此提供合适的解决方案。

excel xml xslt-1.0 xslt-2.0 xpath-2.0
1个回答
0
投票
<input> <item>Lorem ipsum "alpha" dolor sit amet, consectetur "bravo" adipiscing elit "charlie".</item> <item>"Delta" sed do eiusmod tempor "echo" incididunt ut labore et dolore magna aliqua.</item> </input>

XSLT 2.0

© www.soinside.com 2019 - 2024. All rights reserved.