如何使用xslt通过xml从标签获取值
你好,如果我直接提供像 value 这样的逻辑(
),则意味着它可以正确获取,
如果假设我尝试使用某些逻辑(例如
<xsl:variable name ="del50k" select ="(translate(substring-after(value,' '),' ','~'))"/>
<xsl:value-of select="concat(substring(value, 1, 5), ',',substring(substring-before(value,' '),6), ',',$del50k)" />
for ) 来获取这个 xml
<swift>
<message>
<block2 type="input">
<messageType>102</messageType>
<receiverAddress>BKTRUS33XBRD</receiverAddress>
<messagePriority>N</messagePriority>
</block2>
<block3>
<tag>
<name>32</name>
<value>praveen</value>
</tag>
<tag>
<name>42</name>
<value>pubby</value>
</tag>
</block3>
<block4>
<tag>
<name>32A</name>
<value>051008EUR1009.43</value>
</tag>
<tag>
<name>77</name>
<value>PUBBYPRAVZ</value>
</tag>
<tag>
<name>21</name>
<value>UK</value>
</tag>
<tag>
<name>21</name>
<value>USA</value>
</tag>
<tag>
<name>50K</name>
<value>
0601/045788775099
shanmu
MENENDEZ Y PELAYOA CORUNA SPA
</value>
</tag>
<tag>
<name>50K</name>
<value>
0501/045788775099
Praveen
MENENDEZ Y PELAYOA CORUNA SPA
</value>
</tag>
<tag>
<name>76</name>
<value>shanmu</value>
</tag>
</block4>
</message>
</swift>
`
我已经应用了这个 xslt 逻辑,如下所示
<xsl:template match="swift/message/block4/tag [name='21']">
<xsl:value-of select="value"/>,<xsl:text/>
<xsl:variable name="posi" select="position()"/>
<xsl:apply-templates select="../../block4/tag [name='50K'] [position()=$posi]"/>clrf
</xsl:template>
<xsl:template match="/swift/message/block4/tag [name='50K']">
<xsl:variable name ="del50k" select ="(translate(substring-after(value,' '),' ','~'))"/>
<xsl:value-of select="concat(substring(value, 1, 5), ',',substring(substring-before(value,' '),6), ',',$del50k)" />
</xsl:template>
预期结果 TAG 50k 剩余标签正在工作
UK,0601/,045788775099,shanmu~MENENDEZ Y 佩拉约亚科鲁尼亚水疗中心 美国,0501/,045788775099,Praveen~MENENDEZ Y PELAYOA CORUNA SPA
hi if i provide a logic directly like value( <xsl:value-of select="value"/>
)means it was fetching properly
if suppose if i m trying to fetch with some logic like
<xsl:variable name ="del50k" select ="(translate(substring-after(value,'
'),'
','~'))"/>
<xsl:value-of select="concat(substring(value, 1, 5), ',',substring(substring-before(value,'
'),6), ',',$del50k)" />
for this xml
<swift>
<message>
<block2 type="input">
<messageType>102</messageType>
<receiverAddress>BKTRUS33XBRD</receiverAddress>
<messagePriority>N</messagePriority>
</block2>
<block3>
<tag>
<name>32</name>
<value>praveen</value>
</tag>
<tag>
<name>42</name>
<value>pubby</value>
</tag>
</block3>
<block4>
<tag>
<name>32A</name>
<value>051008EUR1009.43</value>
</tag>
<tag>
<name>77</name>
<value>PUBBYPRAVZ</value>
</tag>
<tag>
<name>21</name>
<value>UK</value>
</tag>
<tag>
<name>21</name>
<value>USA</value>
</tag>
<tag>
<name>50K</name>
<value>
0601/045788775099
shanmu
MENENDEZ Y PELAYOA CORUNA SPA
</value>
</tag>
<tag>
<name>50K</name>
<value>
0501/045788775099
Praveen
MENENDEZ Y PELAYOA CORUNA SPA
</value>
</tag>
<tag>
<name>76</name>
<value>shanmu</value>
</tag>
</block4>
</message>
</swift>
`
i have applied this xslt logic like this bellow
<xsl:template match="swift/message/block4/tag [name='21']">
<xsl:value-of select="value"/>,<xsl:text/>
<xsl:variable name="posi" select="position()"/>
<xsl:apply-templates select="../../block4/tag [name='50K'] [position()=$posi]"/>clrf
</xsl:template>
<xsl:template match="/swift/message/block4/tag [name='50K']">
<xsl:variable name ="del50k" select ="(translate(substring-after(value,'
'),'
','~'))"/>
<xsl:value-of select="concat(substring(value, 1, 5), ',',substring(substring-before(value,'
'),6), ',',$del50k)" />
</xsl:template>
Expected result TAG 50k remaining tags are working
UK,0601/,045788775099,shanmu~MENENDEZ Y PELAYOA CORUNA SPA
USA,0501/,045788775099,Praveen~MENENDEZ Y PELAYOA CORUNA SPA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在提供的 XML 文档中,不存在
tag
元素,其name
子元素具有字符串值'21'
并且(tag 元素)是
block4
元素的子元素,而该元素又是message
元素的子元素,而message
元素又是swift
元素的子元素。因此,根本不应用该模板,并且不会产生它必须产生的结果。
In the provided XML document there is no
tag
element whosename
child has string value'21'
and that (thetag
element) is a child of ablock4
element that is a child of amessage
element that is a child of aswift
element.Therefore, the template isn't applied at all and the results it must produce are not produced.