编号表,其中多个实例计数为一个表XSLT 3.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 </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>
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会检查您是否可以使用
XSL:number count =“某些模式匹配您要计数的元素” level =“任何”
在xslt 3中似乎给出了您在注释输出中拥有的数字在另一个评论中。当然,您不想输出评论,您希望在
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 3seems 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 thexsl:next-match
in that case.