Jump to content

predicat


hibou57

Recommended Posts

hi all,using xslt (for exemple), one may check that an « id » attribut exist, using [@id]. But in my opinion, it lakes logical consistency :), while there is no (in the state of my knowlegde) a predicat for testing the non-existence of a particular attribut, for exemple.Do someone know about it ?Is there a way to bypass this feature lacking ? (with very light coding)Best regards and thanks

Link to comment
Share on other sites

First stop: This is an XSLT question and there is another forum for it.As for the question itself. As far as I know XSLT only selects something if it exist. You may apply conditional statements for the XSLT to do something if the attribute doesn't exist and tell it to do nothing if it does. In other words: reverse the effect.Example(an altered version of a test file I have used here):

<?xml version="1.0" encoding="windows-1251"?><!-- DWXMLSource="test.xml" --><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="windows-1251"/><xsl:template match="/site/images">	<xsl:for-each select="image">  <xsl:choose>  	<xsl:when test="@id">    <xsl:variable name="location" select="location" />    <xsl:variable name="description" select="description" />    <img src="{$location}" alt="{$description}" /><br />  	</xsl:when>  	<xsl:otherwise>    <xsl:text>This is a text that will be shown if the image doesn't have an ID. If you remove this XSLT text element, the XSLT won't do anything if the image doesn't have an ID. The same way you may make the XSLT do something only if the image doesn't have an ID.</xsl:text><br />  	</xsl:otherwise>  </xsl:choose>	</xsl:for-each></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Thanks for this answer Boen,I've already tryed a way like this one. It work, of course. But the questions were about a most proper and explicit way of doing that. WXell, as you said, it seems that there is no explicit way to do this, and I did not found any on the web. So xslt lack logical consistencies. I will do with the state of it.Thanks for allP.S. I'm sorry for having asked this at a bad location, I will take more care the next time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...