编号表,其中多个实例计数为一个表XSLT 3.0

发布于 2025-02-01 19:25:14 字数 5403 浏览 2 评论 0原文

给定此XML:

    <preliminaryRqmts>
    <!-- Table 1 -->
    <reqCondGroup>
          <reqCondNoRef>
                <reqCond>Lorem ipsum</reqCond>
          </reqCondNoRef>
    </reqCondGroup>
    <!-- Table 2 -->
    <reqPersons>
          <person man="A">
                <personCategory personCategoryCode="Chemical technician"/>
                <personSkill skillLevelCode="sk02"/>
                <trade>Cleaner</trade>
                <estimatedTime unitOfMeasure="h">1,0</estimatedTime>
          </person>
    </reqPersons>
    <reqPersons>
          <person man="B">
                <personCategory personCategoryCode="Operator"/>
                <personSkill skillLevelCode="sk02"/>
                <trade>Painter</trade>
                <estimatedTime unitOfMeasure="h">1,0</estimatedTime>
          </person>
    </reqPersons>
    <reqPersons>
          <person man="B">
                <personCategory personCategoryCode="Operator"/>
                <personSkill skillLevelCode="sk03"/>
                <trade>Rider</trade>
                <estimatedTime unitOfMeasure="h">0,8</estimatedTime>
          </person>
    </reqPersons>
    <!-- Table 3 -->
    <reqSafety>
      <noSafety/>
   </reqSafety>
</preliminaryRqmts>
<taskDefinition>
    <task>
       <taskDescr>
          <simplePara>Lorem ipsum</simplePara>
       </taskDescr>
    </task>
    <preliminaryRqmts>
       <!-- Table 4 -->
       <reqCondGroup>
          <noConds/>
       </reqCondGroup>
       <!-- Table 5 -->
       <reqPersons>
          <person man="A">
             <personCategory personCategoryCode="Basic user"/>
             <trade>Operator</trade>
             <estimatedTime unitOfMeasure="h">0,3</estimatedTime>
          </person>
       </reqPersons>
       <!-- Table 6 -->
       <reqSpares>
          <noSpares/>
       </reqSpares>
    </preliminaryRqmts>
</taskDefinition>

输出表标题时必须包括表号。 &lt; reqpersons&gt;可能具有多个兄弟姐妹,但它们被视为一个表。因此,在提供的XML中,前三个reqpersons被计为一个表,表2。reqpersons不是必需的元素,因此可以有&lt; preliminaryrqmts&gt;没有任何&lt; reqpersons&gt;

当有多个以上的preliminaryrqmts带有reqpersons时,我很难获得reqpersons的正确表编号。最初,我有&lt; xsl:value of select =“ if(exting :: reqpersons),然后1 else 0”/&gt;。当有多个preliminaryrqmts/reqpersons时,这将失败。

这是表编号和重新定位的模板。只有第一个reqpersons获得标题和表号。表计数中忽略了任何pater-siblings :: reqpersons。我需要修复&lt; xsl:变量name =“ Countper” select =“ count(Ancestor-OR-Self :: PreliminaryRQMTS/REQPERSONS [1]))/&gt;,其余部分编号正常工作。

    <xsl:template match="reqPersons[1]">
      <fo:block>
        <xsl:text>Table&#xa0;</xsl:text>
        <xsl:call-template name="number-tables"/>
        <xsl:text>&#xa0;&#xa0;Required persons</xsl:text>
      </fo:block>
      <fo:table>
        <xsl:call-template name="reqPersonTableBody"/>
      </fo:table>
    </fo:block>
  </xsl:template>

<xsl:template match="reqPersons">
    <fo:block>
      <fo:table>
        <xsl:call-template name="reqPersonTableBody"/>
      </fo:table>
    </fo:block>
</xsl:template>

<xsl:template name="reqPersonTableBody">
    <fo:table-column column-number="1" column-width="33%"/>
    <fo:table-column column-number="2" column-width="33%"/>
    <fo:table-column column-number="3" column-width="33%"/>
    <fo:table-header>
      <fo:table-row>
        <fo:table-cell>
          <fo:block>Person</fo:block>
        </fo:table-cell>
        <fo:table-cell>
          <fo:block>Category</fo:block>
        </fo:table-cell>
        <fo:table-cell>
          <fo:block>Skill level</fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-header>
    <fo:table-body>
      <xsl:apply-templates select="personnel | person"/>
    </fo:table-body>
  </xsl:template>

  <xsl:template name="number-tables">
    <xsl:variable name="countreqCondTables" select="count(preceding::reqCondGroup|preceding::reqSupportEquips|preceding::reqSupplies|preceding::reqSpares|preceding::reqTechInfoGroup)"/>
    <xsl:variable name="countPer" select="count(ancestor-or-self::preliminaryRqmts/reqPersons[1])"/>
    <xsl:variable name="countSelfPer" select="count(ancestor-or-self::reqPersons[1])"/>

    <xsl:variable name="countSelf" select="count(ancestor-or-self::table|ancestor-or-self::reqCondGroup|ancestor-or-self::reqSupportEquips|ancestor-or-self::reqSupplies|
      ancestor-or-self::reqSpares|ancestor-or-self::reqTechInfoGroup)"/>
    
    <xsl:value-of select="$countPer+$countSelf+$countSelfPer+$countreqCondTables"/>
  </xsl:template>

Given this XML:

    <preliminaryRqmts>
    <!-- Table 1 -->
    <reqCondGroup>
          <reqCondNoRef>
                <reqCond>Lorem ipsum</reqCond>
          </reqCondNoRef>
    </reqCondGroup>
    <!-- Table 2 -->
    <reqPersons>
          <person man="A">
                <personCategory personCategoryCode="Chemical technician"/>
                <personSkill skillLevelCode="sk02"/>
                <trade>Cleaner</trade>
                <estimatedTime unitOfMeasure="h">1,0</estimatedTime>
          </person>
    </reqPersons>
    <reqPersons>
          <person man="B">
                <personCategory personCategoryCode="Operator"/>
                <personSkill skillLevelCode="sk02"/>
                <trade>Painter</trade>
                <estimatedTime unitOfMeasure="h">1,0</estimatedTime>
          </person>
    </reqPersons>
    <reqPersons>
          <person man="B">
                <personCategory personCategoryCode="Operator"/>
                <personSkill skillLevelCode="sk03"/>
                <trade>Rider</trade>
                <estimatedTime unitOfMeasure="h">0,8</estimatedTime>
          </person>
    </reqPersons>
    <!-- Table 3 -->
    <reqSafety>
      <noSafety/>
   </reqSafety>
</preliminaryRqmts>
<taskDefinition>
    <task>
       <taskDescr>
          <simplePara>Lorem ipsum</simplePara>
       </taskDescr>
    </task>
    <preliminaryRqmts>
       <!-- Table 4 -->
       <reqCondGroup>
          <noConds/>
       </reqCondGroup>
       <!-- Table 5 -->
       <reqPersons>
          <person man="A">
             <personCategory personCategoryCode="Basic user"/>
             <trade>Operator</trade>
             <estimatedTime unitOfMeasure="h">0,3</estimatedTime>
          </person>
       </reqPersons>
       <!-- Table 6 -->
       <reqSpares>
          <noSpares/>
       </reqSpares>
    </preliminaryRqmts>
</taskDefinition>

I have to include the Table number when outputting the table title. <reqPersons> may have multiple siblings but they are counted as one table. So in the XML provided, the first three reqPersons are counted as one table, Table 2. reqPersons is not a required element so there could be <preliminaryRqmts> without any <reqPersons>.

I am having trouble getting the correct table numbering for reqPersons when there is more than one preliminaryRqmts with a reqPersons. Originally I had <xsl:value-of select="if(preceding::reqPersons) then 1 else 0"/>. This fails when there are multiple preliminaryRqmts/reqPersons.

Here are the templates for the table numbering and reqPersons. Only the first reqPersons gets a title and table number. Any following-siblings::reqPersons are ignored in the table count. I need help with fixing <xsl:variable name="countPer" select="count(ancestor-or-self::preliminaryRqmts/reqPersons[1])"/>, the rest of the numbering is working properly.

    <xsl:template match="reqPersons[1]">
      <fo:block>
        <xsl:text>Table </xsl:text>
        <xsl:call-template name="number-tables"/>
        <xsl:text>  Required persons</xsl:text>
      </fo:block>
      <fo:table>
        <xsl:call-template name="reqPersonTableBody"/>
      </fo:table>
    </fo:block>
  </xsl:template>

<xsl:template match="reqPersons">
    <fo:block>
      <fo:table>
        <xsl:call-template name="reqPersonTableBody"/>
      </fo:table>
    </fo:block>
</xsl:template>

<xsl:template name="reqPersonTableBody">
    <fo:table-column column-number="1" column-width="33%"/>
    <fo:table-column column-number="2" column-width="33%"/>
    <fo:table-column column-number="3" column-width="33%"/>
    <fo:table-header>
      <fo:table-row>
        <fo:table-cell>
          <fo:block>Person</fo:block>
        </fo:table-cell>
        <fo:table-cell>
          <fo:block>Category</fo:block>
        </fo:table-cell>
        <fo:table-cell>
          <fo:block>Skill level</fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-header>
    <fo:table-body>
      <xsl:apply-templates select="personnel | person"/>
    </fo:table-body>
  </xsl:template>

  <xsl:template name="number-tables">
    <xsl:variable name="countreqCondTables" select="count(preceding::reqCondGroup|preceding::reqSupportEquips|preceding::reqSupplies|preceding::reqSpares|preceding::reqTechInfoGroup)"/>
    <xsl:variable name="countPer" select="count(ancestor-or-self::preliminaryRqmts/reqPersons[1])"/>
    <xsl:variable name="countSelfPer" select="count(ancestor-or-self::reqPersons[1])"/>

    <xsl:variable name="countSelf" select="count(ancestor-or-self::table|ancestor-or-self::reqCondGroup|ancestor-or-self::reqSupportEquips|ancestor-or-self::reqSupplies|
      ancestor-or-self::reqSpares|ancestor-or-self::reqTechInfoGroup)"/>
    
    <xsl:value-of select="$countPer+$countSelf+$countSelfPer+$countreqCondTables"/>
  </xsl:template>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛放△進行李 2025-02-08 19:25:15

我会检查您是否可以使用XSL:number count =“某些模式匹配您要计数的元素” level =“任何”在xslt 3中

<xsl:param name="table-count-pattern" static="yes" as="xs:string" select="'preliminaryRqmts/reqCondGroup | preliminaryRqmts/reqPersons[1] | preliminaryRqmts/reqSafety | preliminaryRqmts/reqSpares'"/>

<xsl:template _match="{$table-count-pattern}">
    <xsl:comment>computed table <xsl:number _count="{$table-count-pattern}" level="any"/></xsl:comment>
    <xsl:next-match/>
</xsl:template>

似乎给出了您在注释输出中拥有的数字在另一个评论中。当然,您不想输出评论,您希望在fo:block中输出该数字,但是显然可以轻松地调整上述建议。如果需要,如果您对所有需要输出的元素有很多不同的模板您需要编号,使用例如&lt; xsl:apply-templates select =“。”。 mode =“ count”/&gt;。在这种情况下,您可能需要删除XSL:Next-satch

I would check whether you can use xsl:number count="some pattern matching the elements you want to count" level="any" e.g. in XSLT 3

<xsl:param name="table-count-pattern" static="yes" as="xs:string" select="'preliminaryRqmts/reqCondGroup | preliminaryRqmts/reqPersons[1] | preliminaryRqmts/reqSafety | preliminaryRqmts/reqSpares'"/>

<xsl:template _match="{$table-count-pattern}">
    <xsl:comment>computed table <xsl:number _count="{$table-count-pattern}" level="any"/></xsl:comment>
    <xsl:next-match/>
</xsl:template>

seems to give the numbers you have in your comments output in another comment. Of course, you don't want to output a comment, you want to output that number in your fo:block but you can obviously adapt the above suggestion easily. If needed, if you have lots of different templates for all the elements that need to output that count, put the above template in a mode with e.g. mode="count", and in your other templates, where you need to number, use e.g. <xsl:apply-templates select="." mode="count"/>. You will probably want to remove the xsl:next-match in that case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文