• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

XSL question

Hello I have to write a snippet of code that filters out certain values of a parameter on a querystring being passed.

Something like an if statement that says:

if this value of the parameter gets passed, please show this graphic to the end user

Can you think of a skeleton type snippet that I could use?

Thanks,
Midani
0
Midani22
Asked:
Midani22
  • 8
  • 5
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
How does this relate to XSL? Can you clarify some info about what you are doing here... Are you doing this on the server side? Are you programming a plain servlet, or some framework, such as Spring MVC?
0
 
Geert BormansCommented:
It would definitely help if you showed us some XML source.

Generally this is what happens.

In your XSLT you need a global parameter
<xsl:param name="qvalue"/>
(it needs to be top level, so right under the stylesheet element)
in java (or whatever your server architecture is) you can pass in the value for qvalue
(of course you can name the parameter whatever you want)

Rather than having a if statement, you can (and you should be for performance reasons) selective a level above your images
Instead of selecting all images by doing <xsl:apply-templates select="images"/>
use a more selective statement
<xsl:apply-templates select="images[@name = $qvalue]"/>

of course you need to adapt this to the XML and the XSLT you already have
If you post more details, I can give better code,

But at least this gives you the general principle
0
 
Midani22Author Commented:
this is a snippet of code that is working on the page now:


              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=REL&amp;lastpage=SelectDocumentManagement' and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>

The parameter is: parentId and it shows up on this querystring:

https://209.173.134.79:7001/DMTemplateLoaderFLReports?sdate=03/19/2010&edate=03/19/2012&caseid=0&homeid=1&parentid=1&userid=100059&mode=APA&documentFileName=1-CineratorReport.doc&homeId=<xsl:value-of select="../../Home/Id"/>&amp;transId=NA&amp;dmDocumentId=<xsl:value-of select="../../DMDocumentId"/>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Geert BormansCommented:
OK, now I need more info on how you do all of this.

It seems you are constructing the querystring yourself in teh XSLT
and parentId seems a constant, so you just make variable $parentId = 1?
so obviously we need more detail on what is happening

Do you have a server application that gets in a request?
If so, pull the parentId from the get Header.
The framework you are doing this in, will certainly give you access to the individual parameters, not just the entire querystring.
Then you can pass them individualy to the XSLT as parameters

And then what?
Your code is not helping to find out what you really want.
So you need to give us more detail.
- what do you do
- how do you do it
- what do you want to achieve
- what is the source XML
- more context on the XSLT

If you can't get the querystring parameters individually and you need to pull them out of the full querystring you need to do like this (given the querystring is in $querystring

<xsl:variable name="parentId" select="substring-before(substring-after(concat($querystring, '&amp;'), 'parentid='), '&amp;')"/>

Open in new window


note that I concatenated an "&" at the end of the querystring in order for this to also work if paretid happens to be the last parameter
0
 
Midani22Author Commented:
XML and the XLS is here:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<!--
File Name: NavBar.xsl
Purpose: Stylesheet for NavBar

Created: 2003
Author:


-->

<!-- setup defaults for parameters -->
<xsl:param name="screenid" select="'default value'"/>
<xsl:param name="screentitle" select="'default value'"/>
<xsl:param name="menu" select="'START'"/>
<xsl:param name="role" select="'user'"/>
<xsl:param name="image-root"/>
<xsl:param name="displayLifeReview"/>
<xsl:param name="dcode"/>
<xsl:param name="baltrans"/>a
<xsl:param name="vflag"/>
<xsl:param name="accsys"/>
<xsl:param name="disp"/>
<xsl:param name="qbCompanyFileName"/>
<xsl:param name="homeDocumentScheme"/>
<xsl:variable name="space" select="' '"/>
<xsl:variable name="underscore" select="'_'"/>
<xsl:variable name="flag" select="F"/>
<xsl:param name="arrangernotesflag"/>
<xsl:param name="familynotesflag"/>
<xsl:param name="state"/>
<xsl:param name="newPack"/>


<xsl:template match="/">

<script language="JavaScript">
<![CDATA[

function toggle( id ) {

      var submenus = document.all( id );
      for (var j=0; j < submenus.length; j++) {

            var el = submenus.item(j)
            if (el.style.display == "") {
                  el.style.display = "none";
            }
            else {
                  el.style.display = "";
            }
      }
}

]]>
</script>

<TABLE border="0" cellpadding="0" cellspacing="0" width="100%" >

      <TR class="sidebottomBanner">
            <TD width="5" height="10" class="bottomBanner">
                  <IMG><xsl:attribute name="src"><xsl:value-of select="$image-root"/>border.gif</xsl:attribute></IMG>
            </TD>
            <td class="sidebottomBanner"></td>
      </TR>
      <TR class="sidebottomBanner">
            <TD width="5" class="bottomBanner">
                  <IMG><xsl:attribute name="src"><xsl:value-of select="$image-root"/>border.gif</xsl:attribute></IMG>
            </TD>
            <TD>
                  <TABLE border="0" cellpadding="1" cellspacing="2" width="175">
                        <xsl:for-each select="/menus/menu[@name=$menu]/menuitem[role=$role]">
        <xsl:if test="not($baltrans = 'true' and descendant-or-self::node()[@id='CommemorationHome'])">
                              <TR class="sidebottomBanner">
                                    <TD width="2" />
                                    <TD height="25" valign="middle" colspan="2">
                                          <SPAN>
                                                <xsl:attribute name="onclick">validate('<xsl:value-of select="@id"/>');</xsl:attribute>
                                                <xsl:choose>
                                                      <xsl:when test="descendant-or-self::node()[@id=$screenid]">
                                                            <IMG border="0" class="smallNavigation">
                                                                  <xsl:attribute name="SRC"><xsl:value-of select="$image-root"/>navbar/<xsl:value-of select="translate(@title,' ','_')"/>_h.gif</xsl:attribute>
                                                            </IMG>
                                                      </xsl:when>
                                                      <xsl:otherwise>
                                                            <IMG border="0" class="smallNavigation">
                                                                  <xsl:attribute name="SRC"><xsl:value-of select="$image-root"/>navbar/<xsl:value-of select="translate(@title,' ','_')"/>.gif</xsl:attribute>
                                                            </IMG>
                                                      </xsl:otherwise>
                                                </xsl:choose>
                                          </SPAN>
                                    </TD>
                              </TR>
                              <TR class="sidebottomBanner">
                                    <TD height="1" />
                              </TR>
                              <xsl:for-each select="submenuitem">
                                    <TR class="sidebottomBanner">
                                          <xsl:attribute name="ID"><xsl:value-of select="../@id"/></xsl:attribute>
                                          <xsl:if test="not(parent::node()/descendant-or-self::node()[@id=$screenid])">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

                                          <!-- Conditional to see if life review link should be displayed -->
                                          <xsl:if test="@id='LSHome' and $displayLifeReview='D'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='EditDataAll' and $displayLifeReview='L'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

                                          <xsl:if test="@id='EditDataIntroductory' and $displayLifeReview='L'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

                                          <xsl:if test="@id='VisitationEd' and $dcode='CRE'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

                                          <xsl:if test="@id='FuneralEd' and $dcode='CRE'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

                                          <xsl:if test="@id='GatheringEd' and $dcode='BUR'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

                                          <xsl:if test="@id='CeremonyEd' and $dcode='BUR'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='ChoosePackage' and $baltrans='true'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectTransactionsFamily'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='ArrangementConfirmation' and $baltrans='true'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCaseTransactions' and not($accsys='AP' or $accsys='MA' or $accsys='GP' or $accsys='PT')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCaseTransferCase' and not($accsys='HM')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCaseTransfer' and not($accsys='AP' or $accsys='MA' or $accsys='QB' or $accsys='GP' or $accsys='PT')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCategory' and not($accsys='AP' or $accsys='MA' or $accsys='QB' or $accsys='GP' or $accsys='HM' or $accsys='PT')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCaseDocument' and $homeDocumentScheme='New'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCaseForm' and $homeDocumentScheme='New'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectCasePaperProducts' and $homeDocumentScheme='New'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=FD&amp;lastpage=SelectDocumentManagement' and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=FIN&amp;lastpage=SelectDocumentManagement' and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=FORM&amp;lastpage=SelectDocumentManagement' and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=GEN&amp;lastpage=SelectDocumentManagement'and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=PG&amp;lastpage=SelectDocumentManagement' and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>

              <xsl:if test="@id='SelectDMDocuments?generalDocumentType=REL&amp;lastpage=SelectDocumentManagement' and $menu='AP' and not($homeDocumentScheme='New')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>
                    <xsl:if test="@id='EditServicesAll' and $role='Step 2'">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if>
                    <!--xsl:if test="@id='SelectReporting' and not($state='FL')">
                                                <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                          </xsl:if-->
                    <xsl:if test="@id='ChoosePackage' and $newPack='T'">
                                                  <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                            </xsl:if>
                    <xsl:if test="@id='ChooseNewPackage' and not($newPack='T')">
                                                  <xsl:attribute name="STYLE">display:none</xsl:attribute>
                                            </xsl:if>
                                <TD width="2" />
                                    <TD width="13" />
                            <TD>
              <SPAN>
                <!--<xsl:if test="translate(@title,'_',' ')='Casket/Container'"/>-->
                                                <xsl:attribute name="onclick">validate('<xsl:value-of select="@id"/>');</xsl:attribute>
                                                <xsl:choose>
                                                      <xsl:when test="self::node()[@id = $screenid]">
                                                            <xsl:attribute name="CLASS">smallhitnavigation</xsl:attribute>
                                                      </xsl:when>
                                                      <xsl:otherwise>
                                                            <xsl:attribute name="CLASS">smallnavigation</xsl:attribute>
                                                      </xsl:otherwise>
                                                </xsl:choose>
                                                <xsl:value-of select="translate(@title,'_',' ')"/>
                                          </SPAN>
                                    </TD>
                              </TR>
                        </xsl:for-each>  <!-- submenuitem -->
                        <TR class="sidebottomBanner">
                              <TD height="2"/>
                        </TR>
      </xsl:if>
            </xsl:for-each>  <!-- menuitem -->
      </TABLE>
  </TD>
      </TR>
      <TR>
            <TD colspan="2">
                  <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                        <TR>
                              <TD rowspan="2" width="15">
                                    <IMG><xsl:attribute name="src"><xsl:value-of select="$image-root"/>corner.gif</xsl:attribute></IMG>
                              </TD>
                              <TD height="10" class="sidebottomBanner"></TD>
                        </TR>
                        <TR>
                              <TD class="bottomBanner" height="5" width="170"></TD>
                        </TR>
                  </TABLE>
            </TD>
      </TR>
</TABLE>

      <!-- APA only: add adminLogo -->
      <xsl:if test="$menu='APA'">
            <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                  <TR>
                        <TD height="5"/>
                  </TR>
                  <TR>
                        <TD valign="bottom">
                              <IMG><xsl:attribute name="src"><xsl:value-of select="$image-root"/>adminLogo.gif</xsl:attribute></IMG>
                        </TD>
                  </TR>
            </TABLE>
      </xsl:if>
      <!-- Arranger and Family Notes links -->

            <xsl:if test="$screenid='EditDataStatistical' or $screenid='EditDataIntroductory' or $screenid='EditDataDeath'
            or $screenid='EditDataFamily' or $screenid='EditDataReligion' or $screenid='EditDataLifeWork' or $screenid='EditLifeInterests'
            or $screenid='EditLSDataStatistical' or $screenid='EditLSDataFamily' or $screenid='EditLSDataReligion' or $screenid='EditLSDataLifeWork'
            or $screenid='EditLSDataLifeInterests' or $screenid='EditVisitation' or $screenid='EditFuneral' or $screenid='EditCommittal'
            or $screenid='EditFamilyGathering' or $screenid='EditDataBasic' or $screenid='EditLSHome' or $screenid='EditDataAll' or $screenid='EditServicesAll' or $screenid='EditGathering' or $screenid='EditCeremony'">
            <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                  <TR>
                        <TD height="5"/>
                  </TR>
                  <TR>
                        <TD valign="bottom">
                              <a id="2imgDoc" name="2imgDoc">
                    </a>
                    <a class="internalLinkFancy">
                      <xsl:attribute name="href">javascript:openWindowScroll( 'EditDataNotes?type=STAT&amp;imgName=imgDoc&amp;imgName2=2imgDoc&amp;closeWin=false&amp;homeid='+ document.form1.homeid.value+'&amp;parentid='+ document.form1.parentid.value+'&amp;userid='+ document.form1.userid.value+'&amp;caseid='+ document.form1.caseid.value, 650, 850);</xsl:attribute>
                      <!--<img id="imgDoc" name="imgDoc">
                        <xsl:attribute name="src">
                          <xsl:value-of select="$image-root"/>doc2.gif</xsl:attribute>
                        <xsl:attribute name="border">0</xsl:attribute>
                        <xsl:choose>
                                                <xsl:when test="$arrangernotesflag = 'T'">
                                                      <xsl:attribute name="style">display:''</xsl:attribute>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                      <xsl:attribute name="style">display:'none'</xsl:attribute>
                                                </xsl:otherwise>
                                          </xsl:choose>
                      </img>-->Arranger Notes</a>
                     <a id="2img2Doc" name="2img2Doc">
                    </a>
                    <br/>
                    <a class="internalLinkFancy">
                      <xsl:attribute name="href">javascript:openWindowScroll( 'EditDataNotesFamily?type=STAT&amp;imgName=img2Doc&amp;imgName2=2img2Doc&amp;closeWin=false&amp;homeid='+ document.form1.homeid.value+'&amp;parentid='+ document.form1.parentid.value+'&amp;userid='+ document.form1.userid.value+'&amp;caseid='+ document.form1.caseid.value, 650, 850);</xsl:attribute>
                      <!--<img id="img2Doc" name="img2Doc">
                        <xsl:attribute name="src">
                          <xsl:value-of select="$image-root"/>doc2.gif</xsl:attribute>
                        <xsl:attribute name="border">0</xsl:attribute>
                        <xsl:choose>
                                                <xsl:when test="$familynotesflag = 'T'">
                                                      <xsl:attribute name="style">display:''</xsl:attribute>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                      <xsl:attribute name="style">display:'none'</xsl:attribute>
                                                </xsl:otherwise>
                                          </xsl:choose>
                      </img>-->Family Notes</a>                      
                        </TD>
                  </TR>
                  </TABLE>
            </xsl:if>
            <xsl:if test="$screenid='EditServicesAll'">
            <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                  <tr>
                        <td align="left" width="100" class="internalLinkFancy"
                    onmouseover="this.style.cursor='hand'">
                  <xsl:attribute name="onclick">javascript: validate( 'SelectEventSong?eventtype=<xsl:value-of select="EditServicesAll/CaseEvent/EventType"/>&amp;lastpage=EditServicesAll&amp;homeid='+ document.form1.homeid.value+'&amp;parentid='+ document.form1.parentid.value+'&amp;userid='+ document.form1.userid.value+'&amp;caseid='+ document.form1.caseid.value, 650, 850);</xsl:attribute>
                  Music
                </td>
            </tr>
            <tr>
                <td align="left" width="150" class="internalLinkFancy"
                    onmouseover="this.style.cursor='hand'">
                  <xsl:attribute name="onclick">javascript: validate( 'SelectEventReading?eventtype=<xsl:value-of select="EditServicesAll/CaseEvent/EventType"/>&amp;lastpage=EditServicesAll&amp;homeid='+ document.form1.homeid.value+'&amp;parentid='+ document.form1.parentid.value+'&amp;userid='+ document.form1.userid.value+'&amp;caseid='+ document.form1.caseid.value, 650, 850);</xsl:attribute>
                  Verses &amp; Readings
                </td>
            </tr>
            <tr>
                <td align="left" width="125" class="internalLinkFancy"
                    onmouseover="this.style.cursor='hand'">
                  <xsl:attribute name="onclick">javascript: validate( 'SelectEventChecklist?eventtype=<xsl:value-of select="EditServicesAll/CaseEvent/EventType"/>&amp;lastpage=EditServicesAll&amp;homeid='+ document.form1.homeid.value+'&amp;parentid='+ document.form1.parentid.value+'&amp;userid='+ document.form1.userid.value+'&amp;caseid='+ document.form1.caseid.value, 650, 850);</xsl:attribute>
                  Automotive
                </td>
            </tr>
            </TABLE>
            </xsl:if>

            
</xsl:template>
</xsl:stylesheet>
NavBar.xml
0
 
Midani22Author Commented:
on This URL:

https://209.173.134.79:7001/doLogin

do not want it to display "reports" graphic in the doLogin.java file attached.
doLogin.java
0
 
Midani22Author Commented:
html page showing the reporting.gif file that needs to be hidden if a certain parentid parameter gets passed in
frontpageafterlogin.html
0
 
Midani22Author Commented:
something like this, that does not mention the other numbers, for instance, all but 23, 10, 192, 15, 169,189,230

<xsl:if test="@id="SelectReporting' and not($parentid='2,10,192,15,169,189,230')">
<xsl:attribute name="STYLE">display:none<xsl:attribute>

I don't think this is correct, Wonder what would be inclusive of all integers other than the ones listed above.
0
 
Midani22Author Commented:
Hello, my XML file needs to include this variable which gets passed on the querystring of my application.

<xsl:variable name="parentId" select="substring-before(substring-after(concat($querystring, '&'), 'parentid='), '&')"/>

My xml needs to say this:

something like this, that does not mention the other numbers, for instance, ALL BUT the numbers: 23, 10, 192, 15, 169,189,230

<xsl:if test="@id="SelectReporting' and not($parentid='2,10,192,15,169,189,230')">
<xsl:attribute name="STYLE">display:none<xsl:attribute>

I KNOW MY CODE IS NOT CORRECT, Wonder what would be inclusive of all integers other than the ones listed above.
0
 
Geert BormansCommented:
If you are using XSLT2, this will actually work

<xsl:if test="not($parentid=(2,10,192,15,169,189,230))">
because that would be a sequence

in xslt1 you could serialize that to a string

<xsl:if test="not(contains('#2#10#192#15#169#189#230#', concat('#', $parentid, '#')))">
0
 
Midani22Author Commented:
Hi I compared your source -- THANK YOU!!!!!!! :)

I have a question:

mine said:

<xsl:if test="@id="SelectReporting' and not($parentid='2,10,192,15,169,189,230')">

how come you did not put in there the "@id=SelectReporting' -- was this unintentional?
<xsl:if test="not($parentid=(2,10,192,15,169,189,230))">
0
 
Geert BormansCommented:
I did not add that code since it was correct, and I wanted to concentrate on the real issue

Here is the full test

<xsl:if test="@id = 'SelectReporting' and not(contains('#2#10#192#15#169#189#230#', concat('#', $parentid, '#')))">

note that you need to make sure the ' are put correctly
0
 
Midani22Author Commented:
OUTSTANDING THANK YOU
0
 
Geert BormansCommented:
welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now