Project

Profile

Help

Bug #3733 ยป matching-nonmatching.xsl

Anonymous, 2018-03-29 15:55

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:example="http://example.org"
exclude-result-prefixes="xs math"
version="3.0">
<xsl:output method="text"/>
<xsl:variable name="regexp" select="'^[^:]+:([\s\S]+)$'"/>
<xsl:variable name="string" select="'foaf:name'"/>
<xsl:function name="example:analyze-string">
<xsl:analyze-string select="$string" regex="{$regexp}">
<xsl:matching-substring>
<xsl:sequence select="regex-group(1)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:sequence select="'non-matching'"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:function>
<xsl:template name="start">
<xsl:sequence select="example:analyze-string()"/>
<xsl:sequence select="matches($string,$regexp)"/>
<xsl:sequence select="replace($string,$regexp,'$1')"/>
</xsl:template>
</xsl:stylesheet>
    (1-1/1)