2011-02-06 37 views
0

我不能得到这个工作,所以需要一些帮助......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> 

这其实是一个文本记录包裹成<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> 

有人能帮助我进一步扩展它。谢谢!

+0

这个问题并不明确。首先,你必须指定你想得到的结果。那么,你提供的字符串没有你描述的属性。请编辑你的问题,并使其合理可理解! –

+0

结果 - 我需要根据匹配操作路由标记元素中的完整值。路由将由自定义设备功能执行。包含在''元素文本具有... 1)的59个字符2)的300个字符的固定记录大小3)记录可与XX或M1 4)开始时的记录用XX我们并不需要开始一个头在221个空格后查找50个指标5)本文中的第一条记录以XX开头6)第二条记录(360列)以M1开头,在221个字符后指示值为50 7)最多可以有50条记录(每条300个字符长度) – Liv2luv

+0

您需要完全重新编写(编辑)您的问题并显示完整(但很小)的示例:字符串,规则和结果。 –

回答

1

有了正确的字符偏移量,这个样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="tag" name="search"> 
     <xsl:param name="pRecordIndex" select="55"/> 
     <xsl:param name="pStringLength" select="string-length()"/> 
     <xsl:choose> 
      <xsl:when test="$pRecordIndex > $pStringLength"/> 
      <xsl:when test="substring(.,$pRecordIndex,2) = 'M1' 
          and 
          substring(.,$pRecordIndex + 223,2) = '50'"> 
       <xsl:text>**test successful**</xsl:text> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:call-template name="search"> 
        <xsl:with-param name="pRecordIndex" 
            select="$pRecordIndex + 300"/> 
        <xsl:with-param name="pStringLength" 
            select="$pStringLength"/> 
       </xsl:call-template> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 
</xsl:stylesheet> 

输出:

**test successful** 

注意:您输入具有字头。

+0

+1大功夫。 – Flack

+0

太棒了,我无法想象这个方向。谢谢!! – Liv2luv

+0

@ Liv2luv:不客气。下次检查你的输入,你会得到更快的答案。 – 2011-02-07 01:32:58