I want to convert XPath value like Z.12.s from Z12s using xslt

后端 未结 2 1916
[愿得一人]
[愿得一人] 2021-01-29 10:08

Please any one help me on converting XPath value to dot (full stop) separated.

E.g: Z12s to Z. 12.after 1st char need put dot and after 2 char dot then every 2 chars do

相关标签:
2条回答
  • 2021-01-29 10:46

    If you don't know the length of the input string, you will need to use a recursive named template for this, such as:

    <xsl:template name="split-string">
        <xsl:param name="string"/>
        <xsl:param name="length" select="1"/>
        <xsl:value-of select="substring($string, 1, $length)"/>
        <xsl:if test="string-length($string) > $length">
            <xsl:text>.</xsl:text>
            <!-- recursive call -->
            <xsl:call-template name="split-string">
                <xsl:with-param name="string" select="substring($string, $length + 1)"/>
                <xsl:with-param name="length" select="2"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    

    Demo: https://xsltfiddle.liberty-development.net/pNmC4HF

    0 讨论(0)
  • 2021-01-29 10:56

    If your address can be over 90 characters, add more if's to the AddressDetail template according the pattern that is in the template.

        <xsl:template match="AddressDetails">
          <xsl:copy>
            <xsl:apply-templates select="node() | @*">
              <xsl:with-param name="address" select="substring(Address, 1, 30)"/>
            </xsl:apply-templates>
          </xsl:copy>
          <xsl:if test="string-length(Address) &gt; 30">
            <xsl:copy>
              <xsl:apply-templates select="node() | @*">
                <xsl:with-param name="address" select="substring(Address, 31, 30)"/>
              </xsl:apply-templates>
            </xsl:copy>
          </xsl:if>
          <xsl:if test="string-length(Address) &gt; 60">
            <xsl:copy>
              <xsl:apply-templates select="node() | @*">
                <xsl:with-param name="address" select="substring(Address, 61, 30)"/>
              </xsl:apply-templates>
            </xsl:copy>
          </xsl:if>
          <!-- etc. -->
        </xsl:template>
    
        <xsl:template match="Address">
          <xsl:param name="address"/>
          <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:value-of select="$address"/>
          </xsl:copy>
        </xsl:template>
    
        <xsl:template match="node()|@*">
          <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
          </xsl:copy>
        </xsl:template>
    
    0 讨论(0)
提交回复
热议问题