0

文字列には多くの 16 進値が含まれており、いくつかの条件に基づいて置換を適用する必要があるため、文字列を独特の方法で変換する必要があります。

文字列に 16 進値が含まれています。

文字列の長さは常に 18 の倍数になります。文字列には 1*18 から 5000*18 回 (1 グループから 5000 グループ) を含めることができます。

今私の出力は、以下の条件に基づいて変換された文字列です

1) Check if the groups 13th character is 4e(13th and 14th character)


  Then, change such a way that starting from 7th to 10th character(4 chars) of the string, from whatever the value is to '4040'


    Also change starting from 11th till 16th(6 chars) to '4ef0f0'
    The 17th and 18th to be '4040'

   The whole group to be changed based on the above


2) If the check fails, no change for the group

入力文字列が 1 つのグループで、12 番目と 13 番目が「4e」の場合の例

<xsl:variable name="inputstringhex"
      select="'005f6f7e8f914e7175'"/>

に変換する必要があります

'005f6f40404ef0f04040'

私は xslt1.0 を使用しており、(再帰が使用されている場合) 分割統治法のみを使用できます。これは、末尾再帰法が大量に使用されると xslt プロセッサがエラーになるためです。

4

1 に答える 1

1

バイナリログ再帰を使用できます (おそらく、それが分割統治の意味ですか? とにかく、この XSLT 1.0 スタイルシート...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*" />

<xsl:variable name="inputstringhex"
      select="'005f6f7e8f914e717512346f7e8f914e7175'"/>

<xsl:template match="/">
  <t>
    <xsl:call-template name="string18s">
      <xsl:with-param name="values" select="$inputstringhex" />
    </xsl:call-template>
  </t>  
</xsl:template>

<xsl:template name="string18s">
  <xsl:param name="values" />
  <xsl:variable name="value-count" select="string-length($values) div 18" />
  <xsl:choose>
    <xsl:when test="$value-count = 0" />
    <xsl:when test="$value-count &gt;= 2">
      <xsl:variable name="half-way" select="floor( $value-count div 2) * 18" />
      <xsl:call-template name="string18s">
        <xsl:with-param name="values" select="substring( $values, 1, $half-way)" />
      </xsl:call-template>
      <xsl:call-template name="string18s">
        <xsl:with-param name="values" select="substring( $values,
         $half-way+1, string-length($values) - $half-way)" />
      </xsl:call-template>      
    </xsl:when>  
    <xsl:otherwise>
      <xsl:call-template name="process-one-string18">
        <xsl:with-param name="value" select="$values" />
      </xsl:call-template>
    </xsl:otherwise>  
  </xsl:choose>
</xsl:template>

<xsl:template name="process-one-string18">
  <xsl:param name="value" />
  <v>
   <xsl:choose>
    <xsl:when test="substring( $value, 13, 2) = '4e'"> 
      <xsl:value-of select="concat( substring( $value, 1, 6),
                                    '40404ef0f04040')" />
    </xsl:when> 
    <xsl:otherwise>
      <xsl:value-of select="$value" />
    </xsl:otherwise> 
   </xsl:choose>
  </v>  
</xsl:template>

</xsl:stylesheet>

...この出力が生成されます...

<t>
  <v>005f6f40404ef0f04040</v>
  <v>12346f40404ef0f04040</v>
</t> 

必要に応じて、出力の値を調整または連結します。入力は $inputstringhex 変数の内容です。このソリューションを使用すると、長さ 5000*18 の入力文字列を 13 レベルの再帰のみで処理できます。

于 2012-08-01T15:17:06.637 に答える