2016-01-21 30 views
0

我无法找到一个可以如何调用一个扩展函数在一个这样的代码:是否可以在属性中调用函数?

<xsl:if test='string-length(normalize-space(body)) &gt; 100'> 
    <a href='/photo/{id}-'> &gt;&gt;&gt;</a><br/> 
</xsl:if> 

我需要'{id}-'后,将呼叫添加到我的foo:translit(human_url)功能,因此结果将是'/photo/{id}-{transliterated_part}',但似乎有没有语法正确的方法来做到这一点!

回答

1

是的,这是完全可能的。只是随便调用你的函数包裹在花括号,是这样的:

<a href='/photo/{id}-{foo:translit(human_url)}'> &gt;&gt;&gt;</a> 

下面是使用用户定义的函数foo:upper-lower()演示,它会返回大写和接收到的参数,用下划线分隔的小写形式:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform exclude-result-prefixes="foo xs" xmlns:foo="bar" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
    <xsl:output encoding="UTF-8" indent="yes" /> 

    <xsl:function name="foo:upper-lower" as="xs:string"> 
     <xsl:param name="input" as="xs:string"/> 
     <xsl:sequence select="concat(upper-case($input),'_',lower-case($input))"/> 
    </xsl:function> 

    <xsl:template match="a"> 
     <a href="/photo/{.}-{foo:upper-lower(.)}"></a> 
    </xsl:template> 
</xsl:transform> 

xsltransform.net demo

输入:

<a>Test</a> 

输出:

<a href="/photo/Test-TEST_test"/> 
相关问题