Subject: RE: [xsl] Number of times apply-templates gets executed. From: "Patel, Viral" <viral.patel@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 7 Jan 2003 11:07:04 -0600 |
First of all thanks to all of you. I just joined the list today and the response was really quick and lot of people out there to help. Anyway here is what I am trying to do: I am taking in search parameters into my xsl called $xslSearchState & $xslSearchText. Then I use those parameters to search the XML doc. I have listed the XML doc as well as the XSL below. Bascially what I am trying to do is search for a community in a given state and display the result. It is possible to have same community name in different counties so we cannot assume that there will be only 1 resultset returned from the search. Given that, if a community is not found then I would like to call another template which would display some kind of ERROR message just ONCE. Some other constraints - county name may not be available for the search. So I was thinking that if I could test and see if the displayCommunity template got applied or not then that will tell me we found a record or not. But I am not sure how to determine how many times that template was applied or not. Thanks XML looks something like this: <record> <state name="Illinois"> <county name="countyABC"> <community name="community123"> .... ALL INFO .... </community> </county> <county name="countyDEF"> <community name="community123"> .... ALL INFO .... </community> </county> .... </state> <state name="Iowa"> ..... </state> </record> XSL looks something like this <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"> <xsl:variable name="xslSearchText"></xsl:variable> <xsl:variable name="xslSearchState"></xsl:variable> <xsl:template match="/"> <xsl:apply-templates select="//state"/> </xsl:template> <xsl:template match="state" mode="stateAndCommunity"> <xsl:if test="@name=$xslSearchState"> <xsl:apply-templates select="county/community"> <xsl:sort select="@name"/> </xsl:apply-templates> </xsl:if> </xsl:template> <xsl:template match="community"> <xsl:if test="@name=$xslSearchText"> <xsl:call-template name="displayCommunity"/> </xsl:if> </xsl:template> <xsl:template match="displaycommunity"> Just basically displaying the content of the node in HTML Table format. </xsl:template> </xsl:stylesheet> -----Original Message----- From: Passin, Tom [mailto:tpassin@xxxxxxxxxxxx] Sent: Tuesday, January 07, 2003 10:21 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Number of times apply-templates gets executed. [ Patel, Viral] > I am new to XSL and I have several questions - some of them > might be really easy ones but I just want to confirm. 1. I > believe its not possible to change the value of > <xsl:variable> once its set - correct? > Correct. > 2. Is there a way to figure out how many times a template was > applied when using <xsl:apply-templates>? > > 3. Is there an easy to implement a counter or a boolean in > xsl? If yes then how? Implementing either one would be fine. > It will be better if you talk about what you want to accomplish rather than procedural steps that you imagine you might want to use. For example, literally there are boolean values in xslt, but it sounds like you might want to set a flag and carry it along. This is not a matter have whether you can "have a boolean". You can do this kind of thing by passing parameters to templates, but it is likely that some other approach will be easier and more understandable. As for counters, in xslt you generally select sets of nodes and then operate on them. If you leave them in document order (as is usually the case), then the position of the current node in that node set (given by the position() function) may do the job you wre thinking that a counter would. It all depends on what you want to do. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Number of times apply-tem, Martinez, Brian | Thread | Re: [xsl] Number of times apply-tem, David Carlisle |
RE: [xsl] Number of times apply-tem, Martinez, Brian | Date | RE: [xsl] Number of times apply-tem, Corey Snow |
Month |