XSLT <xsl:when> ਅਣੁ
ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ
ਅਣੁ <xsl:when> ਦੀ ਵਰਤੋਂ <xsl:choose> ਅਣੁ ਲਈ ਸਬੰਧਤ ਕਾਰਵਾਈ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਨ ਲਈ ਕੀਤੀ ਜਾਂਦੀ ਹੈ。
ਅਣੁ <xsl:when> ਇੱਕ ਪ੍ਰਗਰਾਮ ਨੂੰ ਗਣਨਾ ਕਰਦਾ ਹੈ ਅਤੇ ਜੇਕਰ ਜਾਂਚ ਸਹੀ ਬਣਦੀ ਹੈ ਤਾਂ ਨਿਰਧਾਰਿਤ ਕਾਰਵਾਈ ਨੂੰ ਚਲਾਉਂਦਾ ਹੈ。
ਟਿੱਪਣੀਆਂ:元素 <xsl:when> ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ ਕਈ ਸ਼ਰਤਾਂ ਦੀ ਟੈਸਟਿੰਗ ਜੋ ਕਿ <xsl:choose> ਅਤੇ <xsl:otherwise> ਅਣੁਆਂ ਨਾਲ ਸਬੰਧਤ ਹਨ。
ਗਰੰਥ
<xsl:when test="boolean-expression"> <!-- Content: template --> </xsl:when>
ਅਟਰੀਬਿਊਟ
ਅਟਰੀਬਿਊਟ | ਮੁੱਲ | ਵਰਣਨ |
---|---|---|
test | boolean-expression | ਲਾਜ਼ਮੀ। ਬੌਲੀਨ ਐਕਸਪ੍ਰੈਸ਼ਨ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ。 |
ਉਦਾਹਰਣ
ਉਦਾਹਰਣ 1
ਹੇਠ ਦਾ ਕੋਡ cd ਦੇ price 10 ਤੋਂ ਉੱਪਰ ਹੋਣ ਉੱਤੇ artist ਸਤੰਭ ਵਿੱਚ ਗੁਲਾਬੀ ਪੱਗਲਾ ਰੰਗ ਦੇਣ ਵਾਲਾ ਹੈ:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price>'10'"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
XML ਫਾਈਲ ਦੇਖੋ,XSL ਫਾਈਲ ਦੇਖੋ,ਨਤੀਜਾ ਦੇਖੋ。
ਉਦਾਹਰਣ 2
ਇੱਕ ਨਾਮ "color" ਦਾ ਵਰਗ ਘੋਸ਼ਿਤ ਕੀਤਾ ਹੈ। ਇਸ ਦਾ ਮੁੱਲ ਮੌਜੂਦਾ ਇਲੈਕਟਰੰਸ ਦੇ color ਅਟਰੀਬਿਊਟ ਨੂੰ ਦੇ ਦਿੱਤਾ ਹੈ। ਜੇਕਰ ਮੌਜੂਦਾ ਇਲੈਕਟਰੰਸ ਨੂੰ color ਅਟਰੀਬਿਊਟ ਨਹੀਂ ਹੈ ਤਾਂ "color" ਦਾ ਮੁੱਲ "green" ਹੋਵੇਗਾ:
<xsl:variable name="color"> <xsl:choose> <xsl:when test="@color"> <xsl:value-of select="@color"/> </xsl:when> <xsl:otherwise>green</xsl:otherwise> </xsl:choose> </xsl:variable>