美好的一天。我是XSLT的初学者。我要求为写入文本文件的每一行生成序列号。
我有2个内部for-Loops和一个外部for循环。对于外部for循环控制的每个特定条件,传递到内部2个for循环。第一个内部for循环将几行写入文本文件,然后是第二个内部for循环。
例如,假设第一个内部for循环将3行写入文本文件,然后第二个内部将2行写入文本文件,则输出应该像SeqNo:
1
2
3
4
5
以下是我的XML:
<Envelope>
<Body>
<Get_Compensation_Eligibility_Rules_Response version="v23.2">
<Request_References>
<Compensation_Eligibility_Rule_Reference Descriptor="AAFT Workday Management">
<ID type="WID">1a90d104082a101c6a5b8adb783c0891</ID>
<ID type="Condition_Rule_ID">CONDITION_RULE-6-999</ID>
</Compensation_Eligibility_Rule_Reference>
</Request_References>
<Response_Filter>
<As_Of_Effective_Date>2015-08-04-07:00</As_Of_Effective_Date>
<As_Of_Entry_DateTime>2015-08-04T23:51:56.000-07:00</As_Of_Entry_DateTime>
<Page>1</Page>
<Count>100</Count>
</Response_Filter>
<Response_Results>
<Total_Results>1</Total_Results>
<Total_Pages>1</Total_Pages>
<Page_Results>1</Page_Results>
<Page>1</Page>
</Response_Results>
<Response_Data>
<Compensation_Eligibility_Rule>
<Compensation_Eligibility_Rule_Data>
<Effective_Date>2015-08-04-07:00</Effective_Date>
<Rule_Data>
<Condition_Rule_ID>CONDITION_RULE-6-999</Condition_Rule_ID>
<Rule_Description>AAFT Workday Management</Rule_Description>
<Condition_Item_Data>
<Order>a</Order>
<And_Or_Operator_Reference Descriptor="And">
<ID type="WID">da4e1c34446c11de98360015c5e6daf6</ID>
<ID type="And_Or_Operator_Name">And</ID>
</And_Or_Operator_Reference>
<Relational_Operator_Reference
Descriptor="any in the selection list">
<ID type="WID">d5227566446c11de98360015c5e6daf6</ID>
<ID type="Relational_Operator_Name">any in the selection
list</ID>
</Relational_Operator_Reference>
<Condition_Entry_Option_Reference
Descriptor="Value specified in this filter">
<ID type="WID">da59516c446c11de98360015c5e6daf6</ID>
<ID type="Condition_Entry_Option_Name">Value specified in
this filter</ID>
</Condition_Entry_Option_Reference>
<Source_External_Field_Reference
Descriptor="Organization and Superior Organizations (Compensation)">
<ID type="WID">a82f9b81a414453cbf2b103af7d1484f</ID>
</Source_External_Field_Reference>
<Target_Instance_Reference
Descriptor="AAFT Workday (David Harris)">
<ID type="WID">1a90d104082a101c6485a8ac1a3c0750</ID>
<ID type="Organization_Reference_ID"
>SUPERVISORY_ORGANIZATION-6-327</ID>
</Target_Instance_Reference>
</Condition_Item_Data>
<Condition_Item_Data>
<Order>b</Order>
<And_Or_Operator_Reference Descriptor="And">
<ID type="WID">da4e1c34446c11de98360015c5e6daf6</ID>
<ID type="And_Or_Operator_Name">And</ID>
</And_Or_Operator_Reference>
<Relational_Operator_Reference
Descriptor="in the selection list">
<ID type="WID">d5228d9e446c11de98360015c5e6daf6</ID>
<ID type="Relational_Operator_Name">in the selection
list</ID>
</Relational_Operator_Reference>
<Condition_Entry_Option_Reference
Descriptor="Value specified in this filter">
<ID type="WID">da59516c446c11de98360015c5e6daf6</ID>
<ID type="Condition_Entry_Option_Name">Value specified in
this filter</ID>
</Condition_Entry_Option_Reference>
<Source_External_Field_Reference
Descriptor="Management Level (Compensation)">
<ID type="WID">6c04adc731e645309d41fb9b9dc5de45</ID>
</Source_External_Field_Reference>
<Target_Instance_Reference Descriptor="6 Manager">
<ID type="WID">0e93fa4e0cc94867adb662a0ee8430d5</ID>
<ID type="Management_Level_ID">6_Manager</ID>
</Target_Instance_Reference>
<Target_Instance_Reference Descriptor="5 Director">
<ID type="WID">0b778018b3b44ca3959e498041865645</ID>
<ID type="Management_Level_ID">5_Director</ID>
</Target_Instance_Reference>
<Target_Instance_Reference Descriptor="4 Vice President">
<ID type="WID">679d4d1ac6da40e19deb7d91e170431d</ID>
<ID type="Management_Level_ID">4_Vice_President</ID>
</Target_Instance_Reference>
<Target_Instance_Reference
Descriptor="3 Executive Vice President">
<ID type="WID">0ceb3292987b474bbc40c751a1e22c69</ID>
<ID type="Management_Level_ID"
>3_Executive_Vice_President</ID>
</Target_Instance_Reference>
<Target_Instance_Reference
Descriptor="2 Chief Executive Officer">
<ID type="WID">3de1f2834f064394a40a40a727fb6c6d</ID>
<ID type="Management_Level_ID"
>2_Chief_Executive_Officer</ID>
</Target_Instance_Reference>
<Target_Instance_Reference Descriptor="1 Board of Directors">
<ID type="WID">438baab049b14657b7d52ddb4703cc3e</ID>
<ID type="Management_Level_ID">1_Board_of_Directors</ID>
</Target_Instance_Reference>
</Condition_Item_Data>
</Rule_Data>
<Compensation_Grade_Reference
Descriptor="AAFT Workday Management Grade">
<ID type="WID">1a90d104082a101c6ad761aaeb2408ad</ID>
<ID type="Compensation_Grade_ID">COMPENSATION_GRADE-6-19</ID>
</Compensation_Grade_Reference>
<Compensation_Plan_Reference
Descriptor="AAFT Workday Car Allowance Plan">
<ID type="WID">1a90d104082a101c6b7f66f03dfc08e8</ID>
<ID type="Compensation_Plan_ID">ALLOWANCE_AMOUNT_PLAN-6-14</ID>
</Compensation_Plan_Reference>
<Compensation_Plan_Reference Descriptor="AAFT Merit Plan">
<ID type="WID">c49a621d552b102865843b4496fc91c7</ID>
<ID type="Compensation_Plan_ID">MERIT_PLAN-6-37</ID>
</Compensation_Plan_Reference>
</Compensation_Eligibility_Rule_Data>
</Compensation_Eligibility_Rule>
</Response_Data>
</Get_Compensation_Eligibility_Rules_Response>
</Body>
</Envelope>
我的XSLT在下面:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="1.0">
<xsl:output method="text"></xsl:output>
<xsl:strip-space elements="*"/>
<xsl:template match="Report_Data_Outer">
<xsl:text>Eligibility Rule</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Reference ID</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>And Or Operator</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Relational Operator</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Entry_Option</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Source_External_Field</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Source_Condition_Rule</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Target_Instance</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Boolean</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="Envelope/Body/Get_Compensation_Eligibility_Rules_Response/Response_Data/Compensation_Eligibility_Rule/Compensation_Eligibility_Rule_Data/Rule_Data">
<xsl:variable name="Rule_Description"><xsl:value-of select="(Rule_Description)"/></xsl:variable>
<xsl:variable name="Condition_Rule_ID"><xsl:value-of select="(Condition_Rule_ID)"/></xsl:variable>
<xsl:for-each select="Condition_Item_Data">
<xsl:variable name="And_Or_Operator"><xsl:value-of select="(And_Or_Operator_Reference/ID[2])"/></xsl:variable>
<xsl:variable name="Relational_Operator"><xsl:value-of select="(Relational_Operator_Reference/ID[2])"/></xsl:variable>
<xsl:variable name="Condition_Entry_Option"><xsl:value-of select="(Condition_Entry_Option_Reference/ID[2])"/></xsl:variable>
<xsl:variable name="Source_External_Field"><xsl:value-of select="(Source_External_Field_Reference[1]/@Descriptor)"/></xsl:variable>
<xsl:variable name="Source_Condition_Rule"><xsl:value-of select="(Source_Condition_Rule_Reference[1]/@Descriptor)"/></xsl:variable>
<xsl:variable name="Boolean"><xsl:value-of select="(Filter_Boolean)"/></xsl:variable>
<xsl:for-each select="Target_Instance_Reference">
<xsl:value-of select="position()"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Rule_Description"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Rule_ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$And_Or_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Relational_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Entry_Option"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_External_Field"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_Condition_Rule"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="@Descriptor"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:for-each select="Filter_Boolean">
<xsl:value-of select="position()"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Rule_Description"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Rule_ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$And_Or_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Relational_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Entry_Option"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_External_Field"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_Condition_Rule"/>
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Boolean"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
内部循环基于for-each select="Target_Instance_Reference"
和for-each select="Filter_Boolean"
。我尝试使用位置函数,但它生成如下所示的行:
生成的序列号:1,1,2,3,4,5,6
但它如下(预期):
预期的序列号:1,2,3,4,5,6,7
请求大师,请建议我如何更正我的SeqNo代。
谢谢!
答案 0 :(得分:0)
您的示例似乎无法使用复制/粘贴,我现在没有时间弄清楚原因,但在快速查看样式表后,我认为您应该尝试替换:
<xsl:value-of select="position()"/>
带
<xsl:number level="any" count="Target_Instance_Reference|Filter_Boolean"/>
如果我理解正确的话,选择xsl:for-each
和Target_Instance_Reference
的两个内循环(Filter_Boolean
)中的。
这是一个稍微修改过的XSLT版本,它会生成您请求的序列号。但是,XML输入中不存在Filter_Boolean
,因此如果您仍然收到错误的序列号,则需要使用更好的输入示例更新您的问题。
XML输入
<Envelope>
<Body>
<Get_Compensation_Eligibility_Rules_Response version="v23.2">
<Request_References>
<Compensation_Eligibility_Rule_Reference Descriptor="AAFT Workday Management">
<ID type="WID">1a90d104082a101c6a5b8adb783c0891</ID>
<ID type="Condition_Rule_ID">CONDITION_RULE-6-999</ID>
</Compensation_Eligibility_Rule_Reference>
</Request_References>
<Response_Filter>
<As_Of_Effective_Date>2015-08-04-07:00</As_Of_Effective_Date>
<As_Of_Entry_DateTime>2015-08-04T23:51:56.000-07:00</As_Of_Entry_DateTime>
<Page>1</Page>
<Count>100</Count>
</Response_Filter>
<Response_Results>
<Total_Results>1</Total_Results>
<Total_Pages>1</Total_Pages>
<Page_Results>1</Page_Results>
<Page>1</Page>
</Response_Results>
<Response_Data>
<Compensation_Eligibility_Rule>
<Compensation_Eligibility_Rule_Data>
<Effective_Date>2015-08-04-07:00</Effective_Date>
<Rule_Data>
<Condition_Rule_ID>CONDITION_RULE-6-999</Condition_Rule_ID>
<Rule_Description>AAFT Workday Management</Rule_Description>
<Condition_Item_Data>
<Order>a</Order>
<And_Or_Operator_Reference Descriptor="And">
<ID type="WID">da4e1c34446c11de98360015c5e6daf6</ID>
<ID type="And_Or_Operator_Name">And</ID>
</And_Or_Operator_Reference>
<Relational_Operator_Reference
Descriptor="any in the selection list">
<ID type="WID">d5227566446c11de98360015c5e6daf6</ID>
<ID type="Relational_Operator_Name">any in the selection
list</ID>
</Relational_Operator_Reference>
<Condition_Entry_Option_Reference
Descriptor="Value specified in this filter">
<ID type="WID">da59516c446c11de98360015c5e6daf6</ID>
<ID type="Condition_Entry_Option_Name">Value specified in
this filter</ID>
</Condition_Entry_Option_Reference>
<Source_External_Field_Reference
Descriptor="Organization and Superior Organizations (Compensation)">
<ID type="WID">a82f9b81a414453cbf2b103af7d1484f</ID>
</Source_External_Field_Reference>
<Target_Instance_Reference
Descriptor="AAFT Workday (David Harris)">
<ID type="WID">1a90d104082a101c6485a8ac1a3c0750</ID>
<ID type="Organization_Reference_ID"
>SUPERVISORY_ORGANIZATION-6-327</ID>
</Target_Instance_Reference>
</Condition_Item_Data>
<Condition_Item_Data>
<Order>b</Order>
<And_Or_Operator_Reference Descriptor="And">
<ID type="WID">da4e1c34446c11de98360015c5e6daf6</ID>
<ID type="And_Or_Operator_Name">And</ID>
</And_Or_Operator_Reference>
<Relational_Operator_Reference
Descriptor="in the selection list">
<ID type="WID">d5228d9e446c11de98360015c5e6daf6</ID>
<ID type="Relational_Operator_Name">in the selection
list</ID>
</Relational_Operator_Reference>
<Condition_Entry_Option_Reference
Descriptor="Value specified in this filter">
<ID type="WID">da59516c446c11de98360015c5e6daf6</ID>
<ID type="Condition_Entry_Option_Name">Value specified in
this filter</ID>
</Condition_Entry_Option_Reference>
<Source_External_Field_Reference
Descriptor="Management Level (Compensation)">
<ID type="WID">6c04adc731e645309d41fb9b9dc5de45</ID>
</Source_External_Field_Reference>
<Target_Instance_Reference Descriptor="6 Manager">
<ID type="WID">0e93fa4e0cc94867adb662a0ee8430d5</ID>
<ID type="Management_Level_ID">6_Manager</ID>
</Target_Instance_Reference>
<Target_Instance_Reference Descriptor="5 Director">
<ID type="WID">0b778018b3b44ca3959e498041865645</ID>
<ID type="Management_Level_ID">5_Director</ID>
</Target_Instance_Reference>
<Target_Instance_Reference Descriptor="4 Vice President">
<ID type="WID">679d4d1ac6da40e19deb7d91e170431d</ID>
<ID type="Management_Level_ID">4_Vice_President</ID>
</Target_Instance_Reference>
<Target_Instance_Reference
Descriptor="3 Executive Vice President">
<ID type="WID">0ceb3292987b474bbc40c751a1e22c69</ID>
<ID type="Management_Level_ID"
>3_Executive_Vice_President</ID>
</Target_Instance_Reference>
<Target_Instance_Reference
Descriptor="2 Chief Executive Officer">
<ID type="WID">3de1f2834f064394a40a40a727fb6c6d</ID>
<ID type="Management_Level_ID"
>2_Chief_Executive_Officer</ID>
</Target_Instance_Reference>
<Target_Instance_Reference Descriptor="1 Board of Directors">
<ID type="WID">438baab049b14657b7d52ddb4703cc3e</ID>
<ID type="Management_Level_ID">1_Board_of_Directors</ID>
</Target_Instance_Reference>
</Condition_Item_Data>
</Rule_Data>
<Compensation_Grade_Reference
Descriptor="AAFT Workday Management Grade">
<ID type="WID">1a90d104082a101c6ad761aaeb2408ad</ID>
<ID type="Compensation_Grade_ID">COMPENSATION_GRADE-6-19</ID>
</Compensation_Grade_Reference>
<Compensation_Plan_Reference
Descriptor="AAFT Workday Car Allowance Plan">
<ID type="WID">1a90d104082a101c6b7f66f03dfc08e8</ID>
<ID type="Compensation_Plan_ID">ALLOWANCE_AMOUNT_PLAN-6-14</ID>
</Compensation_Plan_Reference>
<Compensation_Plan_Reference Descriptor="AAFT Merit Plan">
<ID type="WID">c49a621d552b102865843b4496fc91c7</ID>
<ID type="Compensation_Plan_ID">MERIT_PLAN-6-37</ID>
</Compensation_Plan_Reference>
</Compensation_Eligibility_Rule_Data>
</Compensation_Eligibility_Rule>
</Response_Data>
</Get_Compensation_Eligibility_Rules_Response>
</Body>
</Envelope>
XSLT 1.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="1.0">
<xsl:output method="text"></xsl:output>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text>Eligibility Rule</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Reference ID</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>And Or Operator</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Relational Operator</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Entry_Option</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Source_External_Field</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Source_Condition_Rule</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Target_Instance</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>Boolean</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="Envelope/Body/Get_Compensation_Eligibility_Rules_Response/Response_Data/Compensation_Eligibility_Rule/Compensation_Eligibility_Rule_Data/Rule_Data">
<xsl:variable name="Rule_Description"><xsl:value-of select="normalize-space(Rule_Description)"/></xsl:variable>
<xsl:variable name="Condition_Rule_ID"><xsl:value-of select="normalize-space(Condition_Rule_ID)"/></xsl:variable>
<xsl:for-each select="Condition_Item_Data">
<xsl:variable name="And_Or_Operator"><xsl:value-of select="normalize-space(And_Or_Operator_Reference/ID[2])"/></xsl:variable>
<xsl:variable name="Relational_Operator"><xsl:value-of select="normalize-space(Relational_Operator_Reference/ID[2])"/></xsl:variable>
<xsl:variable name="Condition_Entry_Option"><xsl:value-of select="normalize-space(Condition_Entry_Option_Reference/ID[2])"/></xsl:variable>
<xsl:variable name="Source_External_Field"><xsl:value-of select="normalize-space(Source_External_Field_Reference[1]/@Descriptor)"/></xsl:variable>
<xsl:variable name="Source_Condition_Rule"><xsl:value-of select="normalize-space(Source_Condition_Rule_Reference[1]/@Descriptor)"/></xsl:variable>
<xsl:variable name="Boolean"><xsl:value-of select="normalize-space(Filter_Boolean)"/></xsl:variable>
<xsl:for-each select="Target_Instance_Reference">
<xsl:number level="any" count="Target_Instance_Reference|Filter_Boolean"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Rule_Description"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Rule_ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$And_Or_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Relational_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Entry_Option"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_External_Field"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_Condition_Rule"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="@Descriptor"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:for-each select="Filter_Boolean">
<xsl:number level="any" count="Target_Instance_Reference|Filter_Boolean"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Rule_Description"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Rule_ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$And_Or_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Relational_Operator"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Condition_Entry_Option"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_External_Field"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Source_Condition_Rule"/>
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
<xsl:value-of select="$Boolean"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<强>输出强>
Eligibility Rule,Reference ID,And Or Operator,Relational Operator,Entry_Option,Source_External_Field,Source_Condition_Rule,Target_Instance,Boolean
1,AAFT Workday Management,CONDITION_RULE-6-999,And,any in the selection list,Value specified in this filter,Organization and Superior Organizations (Compensation),,AAFT Workday (David Harris)
2,AAFT Workday Management,CONDITION_RULE-6-999,And,in the selection list,Value specified in this filter,Management Level (Compensation),,6 Manager
3,AAFT Workday Management,CONDITION_RULE-6-999,And,in the selection list,Value specified in this filter,Management Level (Compensation),,5 Director
4,AAFT Workday Management,CONDITION_RULE-6-999,And,in the selection list,Value specified in this filter,Management Level (Compensation),,4 Vice President
5,AAFT Workday Management,CONDITION_RULE-6-999,And,in the selection list,Value specified in this filter,Management Level (Compensation),,3 Executive Vice President
6,AAFT Workday Management,CONDITION_RULE-6-999,And,in the selection list,Value specified in this filter,Management Level (Compensation),,2 Chief Executive Officer
7,AAFT Workday Management,CONDITION_RULE-6-999,And,in the selection list,Value specified in this filter,Management Level (Compensation),,1 Board of Directors