Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question xsl:when test help please

    Hi All!
    I have a little dillema that my xsl-illiterate brain just cannot get around. Here is my code:
    Code:
    <xsl:when test="(name()='TKT_NO') and (<xsl:value-of select="./DOC_TYP"/> = 'O') and not(node()='')">
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    The part in red is not formatted right. What I need to do is check the value of the query column DOC_TYP and depending on what it is call the correct javascript function. Can someone help me to understand this? If I take out the highlighted portion the script works fine...
    Andy
    (Management+Coworkers)<>Logic

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    I think the problem might be fundamental XML. Imagine you're an XML parser and you see this:

    Code:
    <xsl:when test="(name()='TKT_NO') and (<xsl:value-of select="./DOC_TYP"/> = 'O') and not(node()='')">
    The test attribute then equals:
    Code:
    test="(name()='TKT_NO') and (<xsl:value-of select="
    The rest of it is not well-formed, so the XML parser bails out, and your XSLT is ignored.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hi Alex,
    Yeah, I was thinking of that. I've been playing around with this, and I've found that I am going about the problem the wrong way, and I still need help. The code I posted before is testing to see what the column name returned from the query is, and if it is TKT_NO then create a hyperlink for each record returned. What I WANT to do is check EACH record, and if DOC_TYP='O' create one hyperlink and if DOC_TYP='T' create a different hyperlink. To do this I would need to loop through the records. Here is the code for the section I'm working on:
    Code:
      <DIV id="Query4Div" style="display: none">
    
        <!-- Section heading -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="2" CELLPADDING="3" BGCOLOR="#637994">
          <TR><TD>
            <FONT COLOR="#ffffff" SIZE="2"><B>
              <xsl:value-of select="/zoom/query4/@query_label"/>:
            </B></FONT>
          </TD></TR>
        </TABLE>
    
        <!-- Column display labels -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="3" BGCOLOR="#858573">
    
          <!-- For each field label -->
          <TR ALIGN="CENTER">
            <xsl:for-each select="/zoom/query4[position()=1]/*">
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
          </TR>
    
          <!-- For each field value -->
          <xsl:for-each select="/zoom/query4">
    
            <TR ALIGN="CENTER">
              <xsl:for-each select="./*">
                <xsl:choose>
    
    
    
    <!-- TKT_NO - Test and add hyperlink when it is not empty -->
    
             <xsl:when test="(name()='TKT_NO') and not(node()='')"> 
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    
    
    <!-- Otherwise - Just show the column data -->
                  <xsl:otherwise>
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <SMALL><xsl:value-of select="."/></SMALL>
                    </TD>
                  </xsl:otherwise>
    
                </xsl:choose>
              </xsl:for-each>
            </TR>
    
          </xsl:for-each>
        </TABLE>
    
      </DIV>
    To add a test for each record wouldn't the test have to go AFTER the otherwise section? Can this even be done this way?
    Andy
    (Management+Coworkers)<>Logic

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    use variable instead xsl:value-of in test, something like that:
    Code:
    <!-- declare $doc_typ and assign a value -->
    <xsl:variable name="doc_typ" select="./DOC_TYP"/>
    <xsl:choose>
    <!-- use $doc_typ -->
    <xsl:when test="(name()='TKT_NO' and $doc_typ = 'O') and not(node()='')">
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1&#37;">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    <!-- another xsl:when test=.... here -->
    <xsl:otherewise><!-- default here --></xsl:otherwise>
    </xsl:choose>
    change to lower case if you generate xhtml/xml and try to validate both the xml, the generated (x)html.
    Code:
      <DIV id="Query4Div" style="display: none">
    
        <!-- Section heading -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="2" CELLPADDING="3" BGCOLOR="#637994">
          <TR><TD>
            <FONT COLOR="#ffffff" SIZE="2"><B>
              <xsl:value-of select="/zoom/query4/@query_label"/>:
            </B></FONT>
          </TD></TR>
        </TABLE>
    
        <!-- Column display labels -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="3" BGCOLOR="#858573">
    
          <!-- For each field label -->
          <TR ALIGN="CENTER">
            <xsl:for-each select="/zoom/query4[position()=1]/*">
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
          </TR>
    
          <!-- For each field value -->
          <xsl:for-each select="/zoom/query4">
    
            <TR ALIGN="CENTER">
              <xsl:for-each select="./*">
                <xsl:choose>
    
    
    
    <!-- TKT_NO - Test and add hyperlink when it is not empty -->
    
             <xsl:when test="(name()='TKT_NO') and not(node()='')"> 
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    
    
    <!-- Otherwise - Just show the column data -->
                  <xsl:otherwise>
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <SMALL><xsl:value-of select="."/></SMALL>
                    </TD>
                  </xsl:otherwise>
    
                </xsl:choose>
              </xsl:for-each>
            </TR>
    
          </xsl:for-each>
        </TABLE>
    
      </DIV>
    Edit: are very few cases when you need for-each, usualy this could be solved using xsl:template and xsl:apply-templates

    best regards
    Last edited by oesxyl; 10-02-2008 at 12:10 AM.

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Hey oesxyl,
    Ok, here is what I did, but it still doesn't work:
    Code:
    <!-- ====================================================================== -->
    <!-- Section F) Division for Query4 - Current Documents           (Query 4) -->
    <!-- ====================================================================== -->
    
      <DIV id="Query4Div" style="display: none">
    
        <!-- Section heading -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="2" CELLPADDING="3" BGCOLOR="#637994">
          <TR><TD>
            <FONT COLOR="#ffffff" SIZE="2"><B>
              <xsl:value-of select="/zoom/query4/@query_label"/>:
            </B></FONT>
          </TD></TR>
        </TABLE>
    
        <!-- Column display labels -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="3" BGCOLOR="#858573">
    
          <!-- For each field label -->
          <TR ALIGN="CENTER">
            <xsl:for-each select="/zoom/query4[position()=1]/*">
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
          </TR>
    
          <!-- For each field value -->
          <xsl:for-each select="/zoom/query4">
    
            <TR ALIGN="CENTER">
              <xsl:for-each select="./*">
    
    <!-- declare $doc_typ and assign a value -->
    <xsl:variable name="doc_typ" select="./DOC_TYP"/>
    
                <xsl:choose>
    
    
    <!-- use $doc_typ -->
    <xsl:when test="(name()='TKT_NO' and $doc_typ != 'O') and not(node()='')">
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    
    
    
    
    <!-- VEND_NO - Test and add hyperlink when it is not empty -->
                  <xsl:when test="(name()='VEND_NO' or name()='ITEM_VEND_NO') and not(node()='')">
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewVendor('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    
    <!-- Otherwise - Just show the column data -->
                  <xsl:otherwise>
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <SMALL><xsl:value-of select="."/></SMALL>
                    </TD>
                  </xsl:otherwise>
    
                </xsl:choose>
              </xsl:for-each>
            </TR>
    
    
          </xsl:for-each>
        </TABLE>
    
      </DIV>
      <!-- End Section F and Query 4 processing -->
    But no dice. This does not set the hyperlink at all, and I think I know why, but I don't know how to fix it. It appears that where the test is taking place the record set hasn't been returned yet, only the column names, and that is what the xsl:test is looking at. I want to look at each returned row of data and asign a hyperlink to the data in column TKT_NO based on the value of the data in DOC_TYP. I think your variable idea is exactly what is needed, but then don't we need to loop through the records to do the work? doesn't this have to happen AFTER xsltherwise where the records are returned? I do apologize if I am confusing, but xml is not my strongest field!
    Andy
    (Management+Coworkers)<>Logic

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by steamngn View Post
    Hey oesxyl,
    Ok, here is what I did, but it still doesn't work:
    But no dice. This does not set the hyperlink at all, and I think I know why, but I don't know how to fix it. It appears that where the test is taking place the record set hasn't been returned yet, only the column names, and that is what the xsl:test is looking at.
    I think is a problem of xpath. When I have this kind of problem I debug outputing the subtree from the xpath expression. Than mean for example:
    Code:
           <!-- this is for test -->
           <xsl:value-of select="/zoom/query4[position()=1]/*"/>
            <xsl:for-each select="/zoom/query4[position()=1]/*">
              <!-- previous test work, now test here -->
              <xsl:value-of select="."/>
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
    this will output something and if not that means that xpath is not correct or xml subtree is empty. Usualy I change xpath untill I fix the problem and move on with debuging.

    I want to look at each returned row of data and asign a hyperlink to the data in column TKT_NO based on the value of the data in DOC_TYP. I think your variable idea is exactly what is needed, but then don't we need to loop through the records to do the work? doesn't this have to happen AFTER xsltherwise where the records are returned? I do apologize if I am confusing, but xml is not my strongest field!
    Andy
    it's no problem, feel free to ask what you need to solve the problem.
    if debuging the xpath don't give results, post please some xml you process and the xslt file, I will try to see what's wrong.

    best regards

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok my friend,
    Here is where I'm at:
    Code:
    <!-- ====================================================================== -->
    <!-- Section F) Division for Query4 - Current Documents           (Query 4) -->
    <!-- ====================================================================== -->
    
      <DIV id="Query4Div" style="display: none">
    
        <!-- Section heading -->
        <TABLE WIDTH="98&#37;" ALIGN="center" BORDER="0" CELLSPACING="2" CELLPADDING="3" BGCOLOR="#637994">
          <TR><TD>
            <FONT COLOR="#ffffff" SIZE="2"><B>
              <xsl:value-of select="/zoom/query4/@query_label"/>:
            </B></FONT>
          </TD></TR>
        </TABLE>
    
        <!-- Column display labels -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="3" BGCOLOR="#858573">
    
          <!-- For each field label -->
          <TR ALIGN="CENTER">
            <xsl:for-each select="/zoom/query4[position()=1]/*">
    <xsl:value-of select="."/>
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
          </TR>
    
          <!-- For each field value -->
          <xsl:for-each select="/zoom/query4">
    
            <TR ALIGN="CENTER">
              <xsl:for-each select="./*">
    
    <!-- declare $doc_typ and assign a value -->
    <xsl:variable name="doc_typ" select="./DOC_TYP"/>
    <xsl:value-of select="."/>
    
                <xsl:choose>
    If I put the xsl:value-of select where it is red, it returns only the first row of data, like this:
    Code:
    Order
    8/26/2008
    1
    31327
    22
    0.00
    35.67
    0.00
    If I put the xsl:value-of select where it is green, it returns all rows of data, like this:
    Code:
    Order
    8/26/2008 
    1
    31327
    22
    0.00
    35.67
    0.00 
    Quote
    5/20/2008
    1
    3403
    1
    537.80
    0.00
    0.00
    So it looks like we are getting back the tree-structure format we need. NOW! As I play with this and learn (by screwing things up repeatedly!), I notice that if I change the select to:
    Code:
    <xsl:value-of select = select="../DOC_TYP"/>
    That it returns 'O' or 'Q' once for each column instead! SO, I am thinking that we need to test and set our variable BEFORE we <xsl:choose> to run each test; if I'm right, then we need a loop (Is that what <xsl:choose> is?) around our <xsl:choose> tags. Am Iclose, or am I way off?
    And thanks for the help. I really appreciate it when someone takes time from their busy day to lend a hand!
    Andy
    Last edited by steamngn; 10-02-2008 at 02:32 PM.
    (Management+Coworkers)<>Logic

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by steamngn View Post
    Ok my friend,
    Here is where I'm at:
    Code:
    <!-- ====================================================================== -->
    <!-- Section F) Division for Query4 - Current Documents           (Query 4) -->
    <!-- ====================================================================== -->
    
      <DIV id="Query4Div" style="display: none">
    
        <!-- Section heading -->
        <TABLE WIDTH="98&#37;" ALIGN="center" BORDER="0" CELLSPACING="2" CELLPADDING="3" BGCOLOR="#637994">
          <TR><TD>
            <FONT COLOR="#ffffff" SIZE="2"><B>
              <xsl:value-of select="/zoom/query4/@query_label"/>:
            </B></FONT>
          </TD></TR>
        </TABLE>
    
        <!-- Column display labels -->
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="3" BGCOLOR="#858573">
    
          <!-- For each field label -->
          <TR ALIGN="CENTER">
            <xsl:for-each select="/zoom/query4[position()=1]/*">
    <xsl:value-of select="."/>
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
          </TR>
    
          <!-- For each field value -->
          <xsl:for-each select="/zoom/query4">
    
            <TR ALIGN="CENTER">
              <xsl:for-each select="./*">
    
    <!-- declare $doc_typ and assign a value -->
    <xsl:variable name="doc_typ" select="./DOC_TYP"/>
    <xsl:value-of select="."/>
    
                <xsl:choose>
    If I put the xsl:value-of select where it is red, it returns only the first row of data, like this:
    Code:
    Order
    8/26/2008
    1
    31327
    22
    0.00
    35.67
    0.00
    that is normal because position() = 1 select only the first nod in the subtree

    If I put the xsl:value-of select where it is green, it returns all rows of data, like this:
    Code:
    Order
    8/26/2008 
    1
    31327
    22
    0.00
    35.67
    0.00 
    Quote
    5/20/2008
    1
    3403
    1
    537.80
    0.00
    0.00
    it's normal too

    So it looks like we are getting back the tree-structure format we need. NOW! As I play with this and learn (by screwing things up repeatedly!), I notice that if I change the select to:
    Code:
    <xsl:value-of select = select="../DOC_TYP"/>
    I guess it's a typo here, this expression can't work.

    That it returns 'O' or 'Q' once for each column instead!
    ?

    SO, I am thinking that we need to test and set our variable BEFORE we <xsl:choose> to run each test;
    yes

    if I'm right, then we need a loop (Is that what <xsl:choose> is?) around our <xsl:choose> tags. Am Iclose, or am I way off?
    xsl:choose is a switch not a loop, is like a multiple if. As you can see from the second set of data, xslt return a subtree of the tree, don't need any loop only the template to process the subtree

    And thanks for the help. I really appreciate it when someone takes time from their busy day to lend a hand!
    Andy
    you are wellcome,

    best regards
    Last edited by oesxyl; 10-02-2008 at 08:46 PM.

  • Users who have thanked oesxyl for this post:

    steamngn (10-03-2008)

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    <xsl:value-of select = select="../DOC_TYP"/>
    ooooops! yes, a typo. sould be:
    Code:
    <xsl:value-of select = "../DOC_TYP"/>
    Before I added the ".." this value was empty, and now it is returning the letter'O' for orders (and 'Q' for quotes,'T' for tickets, etc.) this is now also correct.
    As you can see from the second set of data, xslt return a subtree of the tree, don't need any loop only the template to process the subtree
    FIGURED IT OUT!
    Geesh, it was simple all along:
    Code:
    <!-- Below is new Document Hyperlink test -->
            <xsl:when test="(../DOC_TYP='Order' and name()='TKT_NO') and not(node()='')"> 
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1&#37;">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    
            <xsl:when test="(../DOC_TYP='Ticket' and name()='TKT_NO') and not(node()='')"> 
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCTicket('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    I needed to look for 'Order' instead of 'O', etc (even though 'O' is stored in the database; apparently the app that is calling this xml is converting the 'O' to the more-friendly 'Order' BEFORE it gets to this xml)
    Anyway, thanks so much for your help!
    Andy
    Andy
    Last edited by steamngn; 10-03-2008 at 08:50 PM.
    (Management+Coworkers)<>Logic

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    in this code, both when tests are for the same node 'TKT_NO' but with different DOC_TYP and only the name of the javascript function is different:
    Code:
    <!-- Below is new Document Hyperlink test -->
            <xsl:when test="(../DOC_TYP='Order' and name()='TKT_NO') and not(node()='')"> 
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1&#37;">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCOrder('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    
            <xsl:when test="(../DOC_TYP='Ticket' and name()='TKT_NO') and not(node()='')"> 
                    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">fnViewCTicket('<xsl:value-of select="."/>');
                        </xsl:attribute><xsl:value-of select="."/>
                      </a>
                    </TD>
                  </xsl:when>
    so you can write something like this:
    Code:
    <xsl:template match="TKT_NO">
         <xsl:variable name="jsfun">
           <xsl:choose>
            <xsl:when test="../DOC_TYP = 'Order'">
                <xsl:value-of select="'fnViewCOrder('"/>
            </xsl:when>
            <xsl:when test="../DOC_TYP='Ticket'">
                <xsl:value-of select="'fnViewCTicket('"/>
            </xsl:when>
           </xsl:choose>
         </xsl:variable>
         <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;"  WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">
                            <xsl:value-of select="concat($jsfun,.,');')"/>
                        </xsl:attribute>
                        <xsl:value-of select="."/>
                      </a>
          </TD>
    </xsl:template>
    and somewhere in your code where you want to insert this you call apply-templates for TKT_NO with the correct path:
    Code:
    <xsl:apply-templates select="correct_path_here/TKT_NO"/>
    you can this way to process the tree using only apply-templates for current subtree and xsl:template.
    I don't know if this will work for you, is just an example.
    Edit: A better way, because DOC_TYP is probably before TKT_NO:
    Code:
    <xsl:template match="DOC_TYP">
         <xsl:variable name="fun">
           <xsl:choose>
            <xsl:when test="name() = 'Order'">
                <xsl:value-of select="'fnViewCOrder('"/>
            </xsl:when>
            <xsl:when test="name() = 'Ticket'">
                <xsl:value-of select="'fnViewCTicket('"/>
            </xsl:when>
           </xsl:choose>
         </xsl:variable>
        <xsl:apply_templates select="TKT_NO">
          <xsl:with-param name="jsfun" select="$fun"/>
        </xsl:apply_templates>
    </xsl:template>
    
    <xsl:template match="TKT_NO">
        <xsl:param name="jsfun"/>
         <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;"  WIDTH="1%">
                      <a href="javascript: void(0);">
                        <xsl:attribute name="onclick">
                            <xsl:value-of select="concat($jsfun,.,');')"/>
                        </xsl:attribute>
                        <xsl:value-of select="."/>
                      </a>
          </TD>
    </xsl:template>


    best regards
    Last edited by oesxyl; 10-03-2008 at 10:48 PM.

  • #11
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok,
    I was looking for a way to 'beautify' the code I wrote, and I was also having problems understanding why
    Code:
    <xsl:apply-templates select="correct_path_here/TKT_NO"/>
    would blow up my code no matter where I put it. I'm not sure if I had something wrong or if the app is doing something I don't know about, but I will work with it some more tomorrow. Now, a question:
    If jsfun equals
    Code:
    <xsl:value-of select="'fnViewCTicket('"/>
    and then we concat like this
    Code:
     <xsl:value-of select="concat($jsfun,.,');')"/>
    doesn't that leave out the TKT_NO we need to pass?
    Shouldn't it be
    Code:
     <xsl:value-of select="concat($jsfun,TKT_NO,');')"/>
    instead?
    (Management+Coworkers)<>Logic

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by steamngn View Post
    Ok,
    I was looking for a way to 'beautify' the code I wrote, and I was also having problems understanding why
    Code:
    <xsl:apply-templates select="correct_path_here/TKT_NO"/>
    would blow up my code no matter where I put it. I'm not sure if I had something wrong or if the app is doing something I don't know about, but I will work with it some more tomorrow.
    this will trigger the processing of the tree/subtree but for this the xpath expression correct_path_here/TKT_NO must match that tree/subtree.

    Now, a question:
    If jsfun equals
    Code:
    <xsl:value-of select="'fnViewCTicket('"/>
    and then we concat like this
    Code:
     <xsl:value-of select="concat($jsfun,.,');')"/>
    doesn't that leave out the TKT_NO we need to pass?
    no because is inside of template who match TKT_NO and '.'( dot) is current text node.

    Shouldn't it be
    Code:
     <xsl:value-of select="concat($jsfun,TKT_NO,');')"/>
    instead?
    no, is called from inside of TKT_NO template and in the case from your example the xml must be something like:
    Code:
    <TKT_NO>
       <TKT_NO>content here</TKT_NO>
    </TKT_NO>
    that from the xpath point of view only. In fact this is more complicated because is a recursive call of the same template and I don't know how it work but this is not important here.

    best regards
    Last edited by oesxyl; 10-04-2008 at 12:11 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •