我确信之前已经问过这个问题,我只是没有按照正确的标准进行搜索,或者我一直在寻找这个问题太长时间了,看不到木头的树木。
基本上不是XML / XSL转换的新手,它不是我角色的重要部分,我有一个XSL转换,将XML从Microsoft SSRS报告转换为格式化文本文件,以及我正在尝试做什么计算linenumbering以在正确的位置强制分页:
以下是SSRS的XML输出示例:
<?xml version="1.0" encoding="utf-8"?>
<Report Name="GR_ItemSample.srdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="GR_ItemSample.srdl">
<Item Detail_ItemCode="6407" Detail_Description="SOLU-CORTEF INJ.SOL.250MG ACT-" Detail_UnitOfSale="AOV" Detail_Quantity="1" Detail_UnitPrice="0,00" Detail_Gross="0,00" Detail_Discount1Percentage="0,00" Detail_Discount1Amount="0,00" Detail_Discount2Percentage="0,00" Detail_Discount2Amount="0,00" Detail_Discount3Percentage="0,00" Detail_Discount3Amount="0,00" Detail_Net="0,00" Detail_Lot="TEST123" Detail_VatPercentage="0,0" Detail_MiscDesc2="*** This is a second line description test *******" valueOnlyIdentifier="1" />
<Item Detail_ItemCode="6407" Detail_Description="SOLU-CORTEF INJ.SOL.250MG ACT-" Detail_UnitOfSale="AOV" Detail_Quantity="1" Detail_UnitPrice="0,00" Detail_Gross="0,00" Detail_Discount1Percentage="0,00" Detail_Discount1Amount="0,00" Detail_Discount2Percentage="0,00" Detail_Discount2Amount="0,00" Detail_Discount3Percentage="0,00" Detail_Discount3Amount="0,00" Detail_Net="0,00" Detail_Lot="TEST123" Detail_VatPercentage="0,0" Detail_MiscDesc2="" valueOnlyIdentifier="1" />
<Item Detail_ItemCode="6407" Detail_Description="SOLU-CORTEF INJ.SOL.250MG ACT-" Detail_UnitOfSale="AOV" Detail_Quantity="1" Detail_UnitPrice="0,00" Detail_Gross="0,00" Detail_Discount1Percentage="0,00" Detail_Discount1Amount="0,00" Detail_Discount2Percentage="0,00" Detail_Discount2Amount="0,00" Detail_Discount3Percentage="0,00" Detail_Discount3Amount="0,00" Detail_Net="0,00" Detail_Lot="TEST123" Detail_VatPercentage="0,0" Detail_MiscDesc2="*** This is a second line description test *******" valueOnlyIdentifier="1" />
<Item Detail_ItemCode="6407" Detail_Description="SOLU-CORTEF INJ.SOL.250MG ACT-" Detail_UnitOfSale="AOV" Detail_Quantity="1" Detail_UnitPrice="0,00" Detail_Gross="0,00" Detail_Discount1Percentage="0,00" Detail_Discount1Amount="0,00" Detail_Discount2Percentage="0,00" Detail_Discount2Amount="0,00" Detail_Discount3Percentage="0,00" Detail_Discount3Amount="0,00" Detail_Net="0,00" Detail_Lot="TEST123" Detail_VatPercentage="0,0" Detail_MiscDesc2="" valueOnlyIdentifier="1" />
<Item Detail_ItemCode="6407" Detail_Description="SOLU-CORTEF INJ.SOL.250MG ACT-" Detail_UnitOfSale="AOV" Detail_Quantity="1" Detail_UnitPrice="0,00" Detail_Gross="0,00" Detail_Discount1Percentage="0,00" Detail_Discount1Amount="0,00" Detail_Discount2Percentage="0,00" Detail_Discount2Amount="0,00" Detail_Discount3Percentage="0,00" Detail_Discount3Amount="0,00" Detail_Net="0,00" Detail_Lot="TEST123" Detail_VatPercentage="0,0" Detail_MiscDesc2="*** This is a second line description test *******" valueOnlyIdentifier="1" />
</Report>
这是我的示例xsl文件:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rpt="GR_ItemSample.srdl">
<xsl:output method="text" omit-xml-declaration="yes" encoding="utf-8" media-type="text/plain"/>
<xsl:template match="rpt:Report">
<xsl:variable name="CrLf1" select="' '"/>
<xsl:for-each select="rpt:Item">
<xsl:value-of select="concat(position(),' - ',@Detail_ItemCode,@Detail_Description,@Detail_UnitOfSale,@Detail_Quantity,@Detail_UnitPrice,@Detail_Gross,@Detail_Discount1Percentage,@Detail_Discount1Amount,@Detail_Discount2Percentage,@Detail_Discount2Amount,@Detail_Discount3Percentage,@Detail_Discount3Amount,@Detail_Net,@Detail_Lot,@Detail_VatPercentage,$CrLf1)"/>
<xsl:if test="string-length(@Detail_MiscDesc2) > 0">
<xsl:value-of select="concat(position(),' - ',@Detail_MiscDesc2,$CrLf1)"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
现在当我运行转换时,我得到以下输出,这接近我想要的结果:
1 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
1 - *** This is a second line description test *******
2 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
3 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
3 - *** This is a second line description test *******
4 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
5 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
5 - *** This is a second line description test *******
我正在使用position()在我的for-each循环中显示“行号”,现在当我只有一行在文本文件中打印每行时这是完美的,但是添加了一个新的要求已经请求了第二个描述行,第二个描述行出现在与@ Detail_MiscDesc2相同的项目行中,但它必须出现在Text文件输出的下一行,我的xsl有条件地基于字符串长度@ Detail_MiscDesc2,但是我需要知道此时的累计行数,所以我的示例输出实际上应该是这样的:
1 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
2 - *** This is a second line description test *******
3 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
4 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
5 - *** This is a second line description test *******
6 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
7 - 6407SOLU-CORTEF INJ.SOL.250MG ACT-AOV10,000,000,000,000,000,000,000,000,00TEST1230,0
8 - *** This is a second line description test *******
我需要这个,因为我还必须计算分页符和页眉和页脚,我知道对于我的文件我总共每页只能有22条细节线。我实际上并不需要打印行号(仅适用于此示例)我只需要知道何时达到22行,这样我就可以处理页脚和分页。我更习惯于程序编程语言,这很容易。我知道我不能使用position(),并且需要使用递归模板,但我无法理解如何做到这一点。任何帮助或指示将不胜感激。 我试图尽可能多地提供详细信息而不会太啰嗦(是的,我知道在那里失败了!)但是如果有什么不清楚请告诉我。
由于
答案 0 :(得分:0)
您可以打印position()
之前的项目,而不是打印先前项目的计数,而不是打印count()
,其中包含强制第二行的描述。类似的东西:
count(preceding-sibling::*) + count(preceding-sibling::*[string-length(@Detail_Misc2) > 0])