Project

Profile

Help

problem of result returned by variable

Added by Anonymous over 18 years ago

Legacy ID: #3861078 Legacy Poster: CoucouA (coucou3011)

Hello, primerly; I presente my XML file Code : <?xml version="1.0" encoding='ISO-8859-1'?> <?xml-stylesheet type="text/xsl" href="Devellopez.xsl"?> <LISTE-A><A> <NUM>20-10</NUM> <C> <ANI>non</ANI></C> <S><SIT> <DEP>Aaaa</DEP> <COM>BB</COM> </SIT></S> </A> <A><NUM>20-11</NUM> <C> <ANI>oui</ANI></C> <S><SIT> <DEP>Abbb</DEP> <COM>BB</COM> </SIT></S> </A> <A><NUM>20-12</NUM> <C><ANI>oui</ANI></C> <S><SIT> <DEP>Aaaa</DEP> <COM>BB</COM> </SIT></S> </A> </LISTE-A> the following XSL Code : <?xml version="1.0" encoding="iso-8859-1" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" media-type="text/html; charset=ISO-8859-1" version="4.0"/> <xsl:template match="/"> <html> <body> <table border="0" width="" > <tr><th>Nombre noeud</th> <th>Numero du A</th> </tr> <xsl:call-template name="doc"> <xsl:with-param name="requete" select="document('requete.xml')/requete"/> </xsl:call-template> </table> </body> </html> </xsl:template> <xsl:template name ="doc" match="LISTE-A"> <xsl:param name="requete"/> <xsl:for-each select="//A"> <xsl:choose> <xsl:when test=".//DEP = $requete/DEP and .//ANI= $requete/ANI"> <tr><td><xsl:variable name="num"> <xsl:number level="any" from="LISTE-A"/> </xsl:variable> <xsl:value-of select="$num"/></td> <td><font color="#FF8040"> <xsl:value-of select="NUM"/></font></td> <td><font color="#FF8040"> dep</font></td> <td><font color="blue">ani</font></td></tr> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template></xsl:stylesheet> Je receive right resultat Nombre noeud Numero du A 2 20-11 dep ani Mu problem is at the level when I chage the foolowing instruction <xsl:when test=".//DEP = $requete/DEP and .//ANI= $requete/ANI"> by varible that his content is in the following file test.xml Code : <?xml version="1.0" encoding='ISO-8859-1'?> <test1> <cle>.//DEP = $requete/DEP and .//ANI= $requete/ANI </cle> </test1> In this station i change the XSL file by the following code Code : <?xml version="1.0" encoding="iso-8859-1" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" media-type="text/html; charset=ISO-8859-1" version="4.0"/> <xsl:template match="/"> <html> <body> <table border="0" width="" > <tr><th>Nombre noeud</th> <th>Numero du A</th> </tr> <xsl:call-template name="doc"> <xsl:with-param name="requete" select="document('requete.xml')/requete"/> <xsl:with-param name="varReq1" select="document('test.xml')/test1/cle[1]"/> </xsl:call-template> </table> </body> </html> </xsl:template> <xsl:template name ="doc" match="LISTE-A"> <xsl:param name="requete"/> <xsl:param name="varReq1"/> <xsl:value-of select="$varReq1"/> <xsl:for-each select="//A"> <xsl:choose> <xsl:when test="$varReq1"> <tr><td><xsl:variable name="num"> <xsl:number level="any" from="LISTE-A"/> </xsl:variable> <xsl:value-of select="$num"/> </td> <td><font color="#FF8040"> <xsl:value-of select="NUMERO"/></font></td> <td><font color="#FF8040"> dep</font></td> <td><font color="blue">ani</font></td></tr> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet> result INCORRECT Nombre noeud Numero du A 1 20-10 dep ani 2 20-11 dep ani 3 20-12 dep ani I would that show me the same result as the precedent thanks


Replies (23)

Please register to reply

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3861777 Legacy Poster: Michael Kay (mhkay)

The value of your variable is a nodeset, and when you say test="$varReq1", Saxon simply tests whether the node exists or not. If you want Saxon to parse the content of the node as an XPath expression and evaluate the expression, you need to use the saxon:evaluate() (or saxon:evaluate-node()) extension function. See the examples in the documentation to see how to bind the variables in the expression.

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3862121 Legacy Poster: CoucouA (coucou3011)

I am sorry, i haven't understand where I would put saxon:evaluate-node() thanks

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3862874 Legacy Poster: CoucouA (coucou3011)

in order to resolve mu problem, I would defined the type of param varReq1 e.g <xsl:param name="varReq1" as="xs:boolean"/> but i haven't the changing at result level I think that i build data model for my type variable

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3863067 Legacy Poster: CoucouA (coucou3011)

the following expression includs Xpath expression but it isn't consider as Xpath expression .//DEP = $requete/DEP and .//ANI= $requete/ANI SO I don't know how can I evaluate it Thanks you to my understanding

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3864045 Legacy Poster: Michael Kay (mhkay)

I'm sorry, I don't understand your follow-up messages. It's not clear to me whether you understood my previous response. In fact I think you are going to have to change your design. Although saxon:evaluate() will allow you to dynamically evaluate XPath expressions that have been read from an external file, the scope of XSLT variables is limited to XPath expressions contained within the stylesheet itself, so there is no way a dynamically-created expression can refer to stylesheet variables. Your problem is an XSLT coding question rather than anything specific to Saxon, so I think the right place for you to get help is on the xsl-list at www.mulberrytech.com. It would be a good idea to start be explaining what you are trying to achieve and why you want to use dynamic XPath expressions.

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3866109 Legacy Poster: CoucouA (coucou3011)

I represent my Problem otherwise, So, I re-explain the problem between <!-- --> <xsl:output method="html" media-type="text/html; charset=ISO-8859-1" version="4.0"/> <xsl:template match="/"> <html> <body> <table border="0" width="*" > <tr><th>Nombre noeud</th> <th>Numero du A</th> </tr> <xsl:call-template name="doc"> <xsl:with-param name="requete" select="document('requete.xml')/requete"/> </xsl:call-template> </table> </body> </html> </xsl:template> <xsl:template name ="doc" match="LISTE-A"> <xsl:param name="requete"/> <xsl:call-template name="doc2"> <xsl:with-param name="requete" select="$requete"/> <xsl:with-param name="varReq1" select=".//DEP = $requete/DEP and .//ANI= $requete/ANI"/> </xsl:call-template> </xsl:template> <xsl:template name ="doc2" match="LISTE-A"> <xsl:param name="varReq1"/> <xsl:param name="requete"/> <xsl:value-of select=".//DEP = $requete/DEP and .//ANI= $requete/ANI"/> <xsl:for-each select="//A"> <xsl:choose> <xsl:when test=".//DEP = $requete/DEP and .//ANI= $requete/ANI"> <!-- MY PROBLEM : WHEN I HAVE : test=".//DEP = $requete/DEP and .//ANI= $requete/ANI" the RESUALT is CORRECT WHEN I MAKE test="$varReq1" THE result is NOT CORRECT INSPITE OF content OF varReq1 vraiable is .//DEP = $requete/DEP and .//ANI= $requete/ANI My Question why the result is not same as the result when test=".//DEP = $requete/DEP and .//ANI= $requete/ANI" --> <tr><td><xsl:variable name="num"> <xsl:number level="any" from="LISTE-A"/> </xsl:variable> <xsl:value-of select="$num"/> </td> <td><font color="#FF8040"> <xsl:value-of select="NUMERO"/></font></td> <td><font color="#FF8040"> dep</font></td> <td><font color="blue">ani</font></td></tr> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet> Best regards

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3866183 Legacy Poster: Michael Kay (mhkay)

Yes, I've understood your problem, but you're clearly having some difficulty understanding my response. Let me try to explain it again, more slowly this time. Variables in XPath represent values. The value might be a string, or a boolean, or a node-set (or in XPath 2.0, a node sequence). Variables do not hold XPath expressions, or parts of expressions. If a variable holds the string "2+2=5", the value is a string of five characters. Saxon isn't going to treat this string as an XPath expression and evaluate it to return the boolean value false(). It's just a string, nothing else, just as if the value were "+++++" or "abcde". Similarly, (as in your case) if the value of a variable $x is a node, then when you say <xsl:if test="$x"> you are testing the effective boolean value of the value of $x, which will be true if $x is a node. Saxon isn't going to look inside the node to see if its value is an XPath expression that needs to be evaluated. In fact, standard XSLT doesn't allow you any way of constructing or reading an XPath expression at run-time and evaluating it in this way. Saxon (and some other products) provide extension functions that do this: in Saxon these are called saxon:evaluate() and saxon:evaluate-node(). However, there is a restriction in these functions, which is that the XPath expressions that are read at run-time cannot contain references to variables defined in the stylesheet. So you won't be able to do what you are trying to do even with these extensions. You can probably achieve what you want using a different design, but for me to help you with that, you will need to explain what you are trying to achieve.

RE: problem of result returned by variable - Added by Anonymous over 18 years ago

Legacy ID: #3866267 Legacy Poster: CoucouA (coucou3011)

Thank you very much for this detail It must the time in order to think by what I will trying to achieve.

RE: problem of conversion string to XPATH - Added by Anonymous about 18 years ago

Legacy ID: #3949808 Legacy Poster: CoucouA (coucou3011)

Hello, my problem is indicated in the comment between <!-- PROBLEM --> <?xml version="1.0" encoding="iso-8859-1" ?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" xmlns:dyn="http://exslt.org/dynamic" > <xsl:output method="html" media-type="text/html; charset=ISO-8859-1" version="4.0"/> <xsl:template match="/"> <html> <body> <table border="0" width="*" > <tr><th>Nombre noeud</th> <th>Numero du A</th> </tr> <xsl:call-template name="doc"> <xsl:with-param name="requete" select="document('requete.xml')/requete"/> </xsl:call-template> </table> </body> </html> </xsl:template> <xsl:template name ="doc" match="LISTE-A"> <xsl:param name="requete"/> <xsl:call-template name="doc2"> <xsl:with-param name="requete" select="$requete"/> <xsl:with-param name="varReq1" select="string ('.//ANI!= $requete/ANI and .//DEP != $requete/DEP') "/> </xsl:call-template> </xsl:template> <xsl:template name ="doc2" match="LISTE-A"> <xsl:param name="varReq1"/> <xsl:param name="requete"/> <xsl:value-of select=".//DEP = $requete/DEP and .//ANI= $requete/ANI"/> <xsl:for-each select="//A"> <!-- PROBLEM --> <!-- verify the CONVERTION OF STRING TO XPATH --> <!-- but in receive the error : cannot find a matching 1-argument function named <http://icl.com/saxon> evaluate() failed t compiled stylesheet --> <xsl:value-of select="saxon:evaluate-node($varReq2)"/> <xsl:if test="boolean($varReq2)"> <tr><td><xsl:variable name="num"> <xsl:number level="any" from="LISTE-A"/> </xsl:variable> <xsl:value-of select="$num"/> </td> <td><font color="#FF8040"> <xsl:value-of select="NUMERO"/></font></td> <td><font color="#FF8040"> dep</font></td> <td><font color="blue">ani</font></td></tr> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet>

RE: problem of conversion string to XPATH - Added by Anonymous about 18 years ago

Legacy ID: #3949824 Legacy Poster: Michael Kay (mhkay)

Please in future start a new topic for a new problem! Otherwise it's very difficult to follow the thread. The correct namespace for Saxon 8.x extension functions is http://saxon.sf.net/

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3949956 Legacy Poster: CoucouA (coucou3011)

I have see the example in http://saxon.sourceforge.net/saxon6.5.5/extensions.html <xsl:variable name="fragment">value</xsl:variable> .. <xsl:apply-templates select="saxon:node-set($fragment)" mode="postprocess" xmlns:saxon="http://icl.com/saxon&quot;/> I have insert xmlns:saxon="http://icl.com/saxon" in <xsl:template name ="doc2" match="LISTE-A" xmlns:saxon="http://icl.com/saxon"> but i received the same error

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3949975 Legacy Poster: Michael Kay (mhkay)

Which version of Saxon are you using? The namespace is different between Saxon 6.5.x and Saxon 8.x

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3949982 Legacy Poster: CoucouA (coucou3011)

I am sorry I see the example in http://saxon.sourceforge.net/saxon7.8/extensions.html I have insert xmlns:saxon="http://saxon.sf.net/." in <xsl:template name ="doc2" match="LISTE-A" http://saxon.sf.net/."> and also in stylsheet but I received the same error

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3949996 Legacy Poster: CoucouA (coucou3011)

I have resolve the problem, thank you

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3950021 Legacy Poster: Michael Kay (mhkay)

The namespace is "http://saxon.sf.net/" not "http://saxon.sf.net/.". And the most current documentation is at http://www.saxonica.com/

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3951483 Legacy Poster: CoucouA (coucou3011)

Hello, please I would to assign the value returned by evaluate in the variable, so I write the following instruction <xsl:variable name="var3" select="saxon:evaluate($var2)"/> but I receive the error : static error in XPath expression supplied to saxon:evaluate:Undeclared variable in a standalone expression Transfromation failed : Run-time errors were reported

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3952780 Legacy Poster: Michael Kay (mhkay)

The error message means what it says. The XPath expression contained in $var2 contains a reference to an undeclared variable.

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3953062 Legacy Poster: CoucouA (coucou3011)

Hello, I corrected the error but the result is always eqaul False, in spite of it must post true please can you tell why?

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3953114 Legacy Poster: CoucouA (coucou3011)

I have regulate the last problem, but no result by putting the following test : <xsl:for-each select="//A"> <xsl:if test="select='saxon:evaluate($varReq2)'"> <tr><td><xsl:variable name="num"> <xsl:number level="any" from="LISTE-A"/> </xsl:variable> <xsl:value-of select="$num"/> </td> <td><xsl:value-of select="saxon:evaluate($varReq2)"/></td></tr> </xsl:if> </xsl:for-each> I would known if the syntax of this test is logic?

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3953126 Legacy Poster: Michael Kay (mhkay)

Firstly, I suggest that when you have a new problem, you start a new thread. Secondly, I can't tell you why your expression is returning a different result from the one you expect unless you show me the expression (together with its inputs). I'm beginning to feel that you are using this list rather too readily. Please try to use it only as a last resort when you have tried to fix your bugs by other means, and please take some trouble when posting questions to supply enough information to give people a chance to help you. Gathering such evidence will in fact often enable you to spot the bug by your own efforts.

Exception Loggin - Added by Anonymous about 18 years ago

Legacy ID: #3953906 Legacy Poster: sarvs (sarvs)

Hi, I want to log all the exceptions to a log file. Is there any sample code which I can refer to? Thanks

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3955352 Legacy Poster: CoucouA (coucou3011)

the sample code which you can refer to : <?xml version="1.0" encoding="iso-8859-1" ?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" > <xsl:output method="html" media-type="text/html; charset=ISO-8859-1" version="4.0"/> <xsl:template match="/"> <html> <body> <table border="0" width="*" > <tr><th>Nombre noeud</th> <th>Numero du A</th> </tr> <xsl:call-template name="doc"> <xsl:with-param name="requete" select="document('requete.xml')/requete"/> </xsl:call-template> </table> </body> </html> </xsl:template> <xsl:template name ="doc" match="LISTE-GITES"> <xsl:param name="requete"/> <xsl:call-template name="doc2"> <xsl:with-param name="requete" select="$requete"/> <xsl:with-param name="varReq2" select=".//ANI!= $requete/ANI and .//DEP != $requete/DEP"/> </xsl:call-template> </xsl:template> <xsl:template name ="doc2" match="LISTE-A" > <xsl:param name="requete"/> <xsl:param name="varReq2"/> <xsl:value-of select="$varReq2"/> <xsl:for-each select="//A"> <xsl:if test="select='saxon:evaluate($varReq2)'"> <tr><td><xsl:variable name="num"> <xsl:number level="any" from="LISTE-A"/> </xsl:variable> <xsl:value-of select="$num"/> </td> <td><font color="#FF8040"> <xsl:value-of select="NUM"/></font></td> <td><font color="#FF8040"> DEP</font></td> <td><font color="blue">ANI</font></td> <td><xsl:value-of select="saxon:evaluate($varReq2)" /></td> </tr> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> /**************************/ <?xml version="1.0" encoding='ISO-8859-1'?> <?xml-stylesheet type="text/xsl" href="Devellopez.xsl"?> <LISTE-A><A> <NUM>20-10</NUM> <C> <ANI>non</ANI> </C> <S><SIT> <DEP>Aaaa</DEP> <COM>BB</COM> </SIT> </S> </A> <A> <NUM>20-11</NUM> <C> <ANI>oui</ANI> </C> <S><SIT> <DEP>Abbb</DEP> <COM>BB</COM> </SIT> </S> </A> <A> <NUM>20-12</NUM> <C> <ANI>oui</ANI> </C> <S><SIT> <DEP>Aaaa</DEP> <COM>BB</COM> </SIT> </S> </A> </LISTE-A>

RE: problem of result returned by variable - Added by Anonymous about 18 years ago

Legacy ID: #3955411 Legacy Poster: Michael Kay (mhkay)

This thread has been running for two months, and has wandered around from one problem to another; but you have just posted a piece of code with no explanation. I don't know if the code is supposed to work or not, or if you still have a problem or not. I'm not going to read the whole thread to try to establish the context. Please start a new thread, explaining your problem, without relying on anyone remembering the details of a very tangled conversation.

    (1-23/23)

    Please register to reply