XSLT 为输入 XML 中的每个增量分隔符位置分配变量

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

对于输入 XML:

<EmpJob>
    <EmpJob>
        <ConcatDepartment>+Local_Functions+Group_Functions+Group_Owners+Group_Managers+Group_Leads+Interim_Services</ConcatDepartment>
    </EmpJob>
</EmpJob>

我希望将值分配给 XSLT 中的变量,如下所示。分隔符是 +,它应该在将值分配给 XSLT 中的每个部门变量时递增,以便我可以使用它们获得以下预期输出..

<xsl:value-of select="$departments[1]" /> should return the string "" 
<xsl:value-of select="$departments[2]" /> should return the string "Local_Functions" 
<xsl:value-of select="$departments[3]" /> should return the string "Local_Functions/Group_Functions" 
<xsl:value-of select="$departments[4]" /> should return the string "Local_Functions/Group_Functions/Group_Owners" 
<xsl:value-of select="$departments[5]" /> should return the string "Local_Functions/Group_Functions/Group_Owners/Group_Managers" 
<xsl:value-of select="$departments[6]" /> should return the string "Local_Functions/Group_Functions/Group_Owners/Group_Managers/Group_Leads" 
<xsl:value-of select="$departments[7]" /> should return the string "Local_Functions/Group_Functions/Group_Owners/Group_Managers/Group_Leads/Interim_Services" 
<xsl:value-of select="$departments[8]" /> should return the string "" 
<xsl:value-of select="$departments[9]" /> should return the string "" 
<xsl:value-of select="$departments[10]" /> should return the string "" 

我尝试过

<xsl:variable name="departments" select="tokenize(/EmpJob/EmpJob/ConcatDepartment, '\+')"/>
<xsl:value-of select="$departments[1]" />

返回字符串“”

<xsl:value-of select="$departments[2]" /> 

返回字符串“Local_Functions”

<xsl:value-of select="$departments[3]" /> 

返回字符串“Group_Functions”

<xsl:value-of select="$departments[4]" /> 

返回字符串“Group_Owners”等等...XSLT 的任何帮助都将非常有帮助

xslt xslt-grouping
1个回答
0
投票

要获得您想要的行为,请使用如下表达式:

<xsl:value-of select="$departments[position() le 4]" separator="/"/>

返回字符串:

/Local_Functions/Group_Functions/Group_Owners

注意表达式:

<xsl:value-of select="$departments[position() le 10]" separator="/"/>

将返回:

/Local_Functions/Group_Functions/Group_Owners/Group_Managers/Group_Leads/Interim_Services

而不是空字符串。我不确定应该使用什么逻辑来产生您显示的确切结果。

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