XSLT 1.0 - 递归地查找元素值中的文本组合
我无法使其正常工作,因此需要一些帮助...
我的 xml 看起来
<tag>PV1FEPMEDIRSPT530000030412011-04-08OC.CF.QL0000 XXR50067171277HIPAA5010TEST1470000020812011-07-13-13.25.49.846947071320112600003971A1SUPERPSA SUPERPSA0711201107152011 085 90 KIYEC M1R50067171277HIPAA5010TEST1470000020812011-07-13-13.25.49.846947071320112600003971A1SUPERPSA SUPERPSA0711201107152011 085 50 XIMUK </tag>
实际上是包装在
元素中的文本记录。
在上述标签元素的值中,59个字符的标头之后可以有一条或多条记录。第一个记录位置从第 60 列开始,一直延伸到 360 列。记录大小是固定的,即 300 个字符。此后可能会出现后续记录。
需要递归读取位置 60 和 61(或者说下一条记录 360 和 361)处包含“M1”的元素值,然后在 221 个空格之后查找指示符“50”。
检查固定长度的第一个“M1”指示符和“50”指示符很简单,但是读取字符串的下一部分变得很困难,因为记录数可能最多为 50 条
。当它仅与第一条记录匹配时,我有一个原始的 XSL .. ?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:regexp="http://exslt.org/regular-expressions"
xmlns:exsl="http://exslt.org/common" extension-element-prefixes=" regexp str exsl"
exclude-result-prefixes="regexp str exsl">
<xsl:preserve-space elements="tag"/>
<xsl:output method="text"/>
<xsl:variable name="msg">
<xsl:value-of select="tag/text()"/>
</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="searchRecursive">
<xsl:with-param name="msg835" select="$msg"/>
<xsl:with-param name="m1Indicator" select="60"/>
<xsl:with-param name="indicator" select="283"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="searchRecursive">
<xsl:param name="msg835" />
<xsl:param name="m1Indicator"/>
<xsl:param name="indicator"/>
<xsl:choose>
<xsl:when test="substring($msg835,$m1Indicator,2) = 'M1' and substring($msg835,$indicator,2) = '50'">
**test successful**
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="searchRecursive">
<xsl:with-param name="msg835" />
<xsl:with-param name="m1Indicator" select="$m1Indicator + 300"/>
<xsl:with-param name="indicator" select="$indicator + 300"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
有人可以帮我进一步扩展它吗 谢谢!
I am not able to get this working, so need some help...
My xml looks like
<tag>PV1FEPMEDIRSPT530000030412011-04-08OC.CF.QL0000 XXR50067171277HIPAA5010TEST1470000020812011-07-13-13.25.49.846947071320112600003971A1SUPERPSA SUPERPSA0711201107152011 085 90 KIYEC M1R50067171277HIPAA5010TEST1470000020812011-07-13-13.25.49.846947071320112600003971A1SUPERPSA SUPERPSA0711201107152011 085 50 XIMUK </tag>
this is actually a text record wrapped into <tag/>
elements.
In the above value of tag element, there may be one or more records after the header which has 59 characters. the first record position starts at column 60 and extends upto 360. The record size is fixed, 300 characters. Subsequent records might appear thereafter.
Need to recursively read the element value at position 60 and 61 (or say for next record 360 and 361) contains 'M1' then look for a position after 221 spaces for an indicator '50'.
checking for first 'M1' indicator and '50' indicator at fixed length is simple, but reading next part of the string becomes difficult as the number of records might be upto 50.
I have a primitive XSL when it matches first record only ...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:regexp="http://exslt.org/regular-expressions"
xmlns:exsl="http://exslt.org/common" extension-element-prefixes=" regexp str exsl"
exclude-result-prefixes="regexp str exsl">
<xsl:preserve-space elements="tag"/>
<xsl:output method="text"/>
<xsl:variable name="msg">
<xsl:value-of select="tag/text()"/>
</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="searchRecursive">
<xsl:with-param name="msg835" select="$msg"/>
<xsl:with-param name="m1Indicator" select="60"/>
<xsl:with-param name="indicator" select="283"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="searchRecursive">
<xsl:param name="msg835" />
<xsl:param name="m1Indicator"/>
<xsl:param name="indicator"/>
<xsl:choose>
<xsl:when test="substring($msg835,$m1Indicator,2) = 'M1' and substring($msg835,$indicator,2) = '50'">
**test successful**
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="searchRecursive">
<xsl:with-param name="msg835" />
<xsl:with-param name="m1Indicator" select="$m1Indicator + 300"/>
<xsl:with-param name="indicator" select="$indicator + 300"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Can some one help me extend it further. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用正确的字符偏移量,此样式表:
输出:
注意:您的输入有一个 54 字符标题。
With the correct character offsets, this stylesheet:
Output:
Note: Your input has a 54 characters header.