#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Problem displaying desired output via XSL


    Hi,
    Hope someone can assist me as I'm stuck at the moment.

    I have this XML (shortcut/edited version):
    Code:
    <!-- Line -->
        <buttonNumber>1</buttonNumber>
        <buttonTypeId>1</buttonTypeId>
        <speedDialDisplay/>
        <speedDialNumber/>
        <sipProxy>proxy.com.au</sipProxy>
        <endpoint>
          <phoneNumber>09900001</phoneNumber>
          <buttonDisplayName>09900001</buttonDisplayName>
          <callerDisplayName>09900001</callerDisplayName>
        </endpoint>
      </builtInButtons>
    
    <!-- Monitor -->
        <buttonNumber>2</buttonNumber>
        <buttonTypeId>2</buttonTypeId>
        <speedDialDisplay/>
        <speedDialNumber/>
        <sipProxy>proxy.com.au</sipProxy>
        <endpoint>
          <phoneNumber>09900000</phoneNumber>
          <buttonDisplayName>09900000</buttonDisplayName>
          <callerDisplayName>09900000</callerDisplayName>
        </endpoint>
    
    <!-- Speed Dial -->
    <buttonNumber>3</buttonNumber>
        <buttonTypeId>3</buttonTypeId>
        <speedDialDisplay>Speed Dial Name</speedDialDisplay>
        <speedDialNumber>12345678</speedDialNumber>
        <sipProxy>proxy.com.au</sipProxy>
    
    <!-- Empty -->
          <buttonNumber>4</buttonNumber>
          <buttonTypeId>2</buttonTypeId>
          <speedDialDisplay/>
          <speedDialNumber/>
          <sipProxy>proxy.com.au</sipProxy>
        </buttons>
    The values I'm after are to meet this conditions:
    - buttonTypeId either 2 or 3, and speedDialNumber or phoneNumber are not Empty

    So using this XSL, I AM ABLE TO GET THE VALUES I'M AFTER
    Code:
    <xsl:for-each select="builtInButtons">
       <xsl:if test="buttonTypeId = '2' or buttonTypeId = '3'">
        <xsl:if test="endpoint/phoneNumber != '' or speedDialNumber != ''">
    The issue i have is DISPLAYING THEM, AS THE OUTPUT NEEDS TO BE INCREMENTAL:
    e.g
    if there are 2 items, satisfies the conditions, output as:
    Code:
    item.1=<value>
    item.2=<value>
    if there are 3 items,
    Code:
    item.1=<value>
    item.2=<value>
    item.3=<value>
    I'm able to get the values im after, but displaying it is the problem. using counters, would have fixed the issue easy, however i found the hard way that XSL doesnt do counters.
    there should be other way of approaching this, please help ?
    Thanks for your help.
    Last edited by drgroove; February 27th, 2011 at 12:40 PM. Reason: added code tags for the n00b :D
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,993
    Rep Power
    9397
    The workaround to missing counters is to use templates. Basically, recursive functions.
    You invoke the template on the first match with N=1. It does what it needs to then searches for the next match. If there is one, it calls itself (recursively) with N=N+1.
    Code:
    1. Get first match
    2. Send to template with N=1
       1. Print match
       2. Get next match
       3. Send to template with N=N+1 (=2)
          1. Print match
          2. Get next match
          3. Send to template with N=N+1 (=3)
             ...
    Also: For future reference, use code tags. Copy/paste your code as usual, select it all, and hit the button.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0
    Hi,
    Thanks for that.
    Using that logic, I came up with this template(pls bear with me as im not fully familiar with XSL):

    Code:
    <xsl:template name="displayMonitored">
    	<xsl:param name="monPhoneNumber" />
    	<xsl:param name="monDisplayName" />
    	<xsl:param name="N" />
    	item.<xsl:value-of select="$N"/>=<xsl:value-of select="$monPhoneNumber"/>
    </xsl:template>

    Code:
    <xsl:variable name="N" select="0" />
    Code:
    <xsl:for-each select="voip:VoipHardware/builtInButtons">
       <xsl:if test="buttonTypeId = '2' or buttonTypeId = '3'">
        <xsl:if test="endpoint/phoneNumber != '' or speedDialNumber != ''">
            
            
            <xsl:call-template name="displayMonitored">
    			<xsl:with-param name="monPhoneNumber" select="endpoint/phoneNumber"/>
    			<xsl:with-param name="monDisplayName" select="endpoint/buttonDisplayName" />
    			<xsl:with-param name="N" select="$N + 1" />
    		</xsl:call-template>
    However the output is not incremental:
    item.1=value
    item.1=value

    please help.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,993
    Rep Power
    9397
    You have to call the next template from within the previous template.

    Like
    Code:
    <xsl:template>
    	<xsl:param>
    	...
    
    	print value
    
    	<xsl:if there are more things to print>
    		<xsl:call-template>
    			<xsl:with-param>
    			...
    		</xsl:call-template>
    	</xsl:if>
    </xsl:template>
    There are no loops.
    The XSLT outside the template only does a call-template with the first item. The template then calls itself with the second item; that template then calls itself again with the third item, and so on until it runs out of stuff to print.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0
    There are no loops.
    Im sorry, I'm not sure I understand your latest post..
    without loops, how am i supposed to go through and get the values im after ?

    Also using ur template, how am i suppose to increment my output?

    using my posts/codes so far, would u be able to give me a backbone structure, of how your saying should look like in XSL ?
    as im not sure i understand what ur saying.
    thanks heaps

IMN logo majestic logo threadwatch logo seochat tools logo