当前位置: 动力学知识库 > 问答 > 编程问答 >

xml - Combine XSLT select condition

问题描述:

I am trying to combine two select condition

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:template match="@*|node()">

<catalog>

<xsl:for-each select="offer[contains(

translate(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),

'test')]">

<xsl:copy-of select="."/>

</xsl:for-each>

</catalog>

</xsl:template>

</xsl:transform>

Example:

<catalog>

<offer>

<name>test 1</name>

<delivery>1</delivery>

</offer>

<offer>

<name>test 2</name>

<delivery>2</delivery>

</offer>

</catalog>

I tried to filter more the output by offer[delivery='1'], without success. The desidered output is:

<catalog>

<offer>

<name>test 1</name>

<delivery>1</delivery>

</offer>

</catalog>

http://xsltransform.net/nc4NzRr

网友答案:

Try it this way:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/catalog">
    <xsl:copy>
        <xsl:copy-of select="offer[contains(translate(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'test') and delivery='1']"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Note that:

<xsl:copy-of select="offer[contains(translate(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'test')][delivery='1']"/>

would accomplish the same thing.

分享给朋友:
您可能感兴趣的文章:
随机阅读: