svg4you: Frage zu xpath

Beitrag lesen

Tach Tim,

Mit XPath 2.0 kann man da wohl mehr machen, ...

Ja, dazu mal ein Ansatz mit der neuen XPath-Funktion fn:matches():

<?xml version="1.0" encoding="ISO-8859-1"?>  
<xsl:stylesheet version="2.0"  
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  xmlns:fn="http://www.w3.org/2005/xpath-functions">  
  
  <xsl:template match="root">  
  
    <xsl:variable name="className" select="'b'"/>  
    <xsl:value-of select="for $a in //@* return fn:matches($a,fn:concat('(^|\s)',$className,'(\s|$)'))"/>  
  
  </xsl:template>  
  
</xsl:stylesheet>

Bezogen auf diese XML-Instanz:

<?xml version="1.0" encoding="ISO-8859-1"?>  
<root>  
  
  <node att="a b c" />  
  <node att="a c b" />  
  <node att="a bb c" />  
  <node att="b c d" />  
  <node att="ab cb" />  
  
</root>

ergibt sich: true true false true false ('b' wird bei true also jeweils gefunden).

Man liest sich,
svg4you