Strip prefix on attribute value

For the project I am stuck with XSLT-1.0 / XPATH-1.0 and you need a quick way to remove the string prefix from the attribute values.

Example attribute values:

"cmdValue1", "gfValue2", "dTestCase3"

The values ​​I need are:

"Value1", "Value2", "TestCase3"

I came up with this XPath expression, but it's too slow for my application:

substring(@attr, 1 + string-length(substring-before(translate(@attr, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '..........................'), '.')))

In essence, the above replaces all uppercase characters with dots, and then creates a substring from the original attribute value, starting with the first dot found (the first capital letter char).

Does anyone know a shorter / faster way to do this in XSLT-1.0 / XPATH-1.0?

+4
source share
2 answers

. , :

substring-after(@attr, 
                substring-before(translate(@attr, 
                                           'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                           '..........................'), 
                                 '.'))

, 7-8% ( ).

+1

XSLT 1.0 , , , .

1,5 , . , - :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xml:space="default" exclude-result-prefixes="" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" />
<xsl:template match="/">
<out>
  <xsl:call-template name="removePrefix">
    <xsl:with-param name="prefixedName" select="xml/@attrib" />
  </xsl:call-template>
</out>
</xsl:template>
<xsl:template name="removePrefix">
<xsl:param name="prefixedName" />
<xsl:choose>
  <xsl:when test="substring-before('_abcdefghijklmnopqrstuvwxyz', substring($prefixedName, 1,1))">
    <xsl:call-template name="removePrefix">
      <xsl:with-param name="prefixedName" select="substring($prefixedName,2)" />
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$prefixedName" />
  </xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
+3

Source: https://habr.com/ru/post/1526348/


All Articles