Perl (27 символов):
sub p{$_[0]eq reverse$_[0]}
Ruby (24 символа):
def p(a)a==a.reverse end
Из предложений, сделанных на сегодняшний день, единственное действенное решение - всегда устанавливать значение параметра при вызове шаблона. Например, раньше у меня было:
<xsl:apply-templates select="//xs:complexType[@name='AddressType']" />
Это нужно было изменить на:
<xsl:apply-templates select="//xs:complexType[@name='AddressType']">
<xsl:with-param name="prefix" select="'AcRec'" />
</xsl:apply-templates>
Я действительно хотел бы знать, почему бы не ($ param) и $ param = '' не работают в тесте WHEN, но я может получить значение not ($ param) в инструкции xsl: value-of.
Note: replaced old answer, check history if you want it.
The following input:
<test xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="something"/>
<xs:complexType name="somethingElse"/>
</test>
Fed to the following XSLT:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:template match="/">
<xsl:for-each select="node()">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>
<xsl:template match="xs:complexType">
<xsl:param name="prefix" />
<xsl:variable name="prefix-no-core">
<xsl:choose>
<xsl:when test="not($prefix)">AcRec</xsl:when>
<xsl:when test="$prefix = 'core'"/>
<xsl:when test="$prefix = 'AcRec'">AcRec</xsl:when>
</xsl:choose>
</xsl:variable>
<xs:complexType name="{concat($prefix-no-core, @name)}"/>
</xsl:template>
</xsl:transform>
Gives the following result:
<xs:complexType name="AcRecsomething" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
<xs:complexType name="AcRecsomethingElse" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
I'm not sure what more you're looking for...
Это взлом, но я добился успеха, сначала заключив параметр в оболочку с помощью функции normalize-space () перед тестированием на пустой параметр.
<xsl:value-of select="not(normalize-space($prefix))" />