7 Replies Latest reply: May 22, 2012 8:47 PM by EJP RSS

    XSLT Transformation - using variables in title name

    868211
      Hi,

      Is there a way to set the title attribute of a table tab in XSLT dynamically through xslt? I'm trying to display sections of code which have the title hardcoded and are present in the xml being rendered. I need the title of that section determined dynamically while parsing through the object nodes of the xml.

      Example:
      <table id="Table ID" title="/Object1/attribute1/name" columnCount="3" seqNo="1">

      instead of hardcoding the title name in the XSLT can we pull the name and set it from the xml being processed?

      Thanks,
      Pavan
        • 1. Re: XSLT Transformation - using variables in title name
          EJP
          Certainly. What does the XML fragment look like?
          • 2. Re: XSLT Transformation - using variables in title name
            868211
            <section id="CALCULATION" title="Calculation">
                           <table id="CALCULATION" title="ClientName Calculation Information" columnCount="3" seqNo="1">
                                <xsl:for-each select="//returnableObjects/IntermediateResultsJB/IntermediateResultJB">
                                     <xsl:if test="resultSetName[.='Client Name Calculation Information']">
                                          <xsl:variable name="Variable1" select="resultName"/>
                                          <xsl:variable name="Variable2" select="resultValue"/>
                                          <!--<xsl:variable name="Variable3" select="resultOrder"/>-->
                                          <detailRow>
                                               <!-- <cell type="string">
                                                    <xsl:value-of select="$Variable3"/>
                                               </cell> -->
                                               <cell type="string">
                                                    <xsl:value-of select="$Variable1"/>
                                               </cell>
                                               <cell type="number">
                                                    <xsl:value-of select="$Variable2"/>
                                               </cell>
                                          </detailRow>
                                     </xsl:if>
                                </xsl:for-each>
                           </table>
            </section>
            This is the XSLT above being used. "ClientName Calculation Information" is hardcoded in the xml that is being rendered.

            XML Fragment is given below:
            <IntermediateResultJB>
                              <resultSetName>ResultSetName1</resultSetName>     
                 <resultName>Name</resultName>
                 <resultValue>Value</resultValue>
                 <resultOrder>1</resultOrder>
            </IntermediateResultJB>
            <IntermediateResultJB>
                 <resultSetName>ResultSetName2</resultSetName>
                 <resultName>Name</resultName>
                 <resultValue>Value</resultValue>
                 <resultOrder>2</resultOrder>
            </IntermediateResultJB>
            <IntermediateResultJB>
                 <resultSetName>ResultSetName3</resultSetName>
                 <resultName>Name</resultName>
                 <resultValue>Value</resultValue>
                 <resultOrder>3</resultOrder>
            </IntermediateResultJB>
            I want the XSLT above to use the <resultSetName> value["ClientName Calculation Information" e.g] to be set in the value of the title attribute of the <table> as well as <section>.

            Thanks,
            Pavan

            Edited by: EJP on 23/05/2012 10:08: code tags.
            • 3. Re: XSLT Transformation - using variables in title name
              EJP
              Easy enough but which one? I think you need to nail down your requirement more tightly.
              • 4. Re: XSLT Transformation - using variables in title name
                868211
                Sorry I realise my last post was not clear. So here's my requirement. The fragment below contains the ResultSetName1 value.
                <IntermediateResultJB>
                                  <resultSetName>ResultSetName1</resultSetName>     
                     <resultName>Name</resultName>
                     <resultValue>Value</resultValue>
                     <resultOrder>1</resultOrder>
                </IntermediateResultJB>
                Here's the XSLT again.
                <section id="CALCULATION" title="ResultSetName1">
                               <table id="CALCULATION" title="ResultSetName1" columnCount="3" seqNo="1">
                                    <xsl:for-each select="//returnableObjects/IntermediateResultsJB/IntermediateResultJB">
                                         <xsl:if test="resultSetName[.='Client Name Calculation Information']">
                                              <xsl:variable name="Variable1" select="resultName"/>
                                              <xsl:variable name="Variable2" select="resultValue"/>
                                              <!--<xsl:variable name="Variable3" select="resultOrder"/>-->
                                              <detailRow>
                                                   <!-- <cell type="string">
                                                        <xsl:value-of select="$Variable3"/>
                                                   </cell> -->
                                                   <cell type="string">
                                                        <xsl:value-of select="$Variable1"/>
                                                   </cell>
                                                   <cell type="number">
                                                        <xsl:value-of select="$Variable2"/>
                                                   </cell>
                                              </detailRow>
                                         </xsl:if>
                                    </xsl:for-each>
                               </table>
                </section>
                In this line below,
                <table id="CALCULATION" title="ResultSetName1" columnCount="3" seqNo="1">
                Right now the title is hardcoded. Im going to have many such IntermediateResult objects with different names in the <resultSetName> node and would need to duplicate the <section> and <title> code for each new resultSetName. So I want to use the 1 XSLT above to read in the title name dynamically by using something like "returnableObjects/IntermediateResultsJB/IntermediateResultJB/resultSetName".
                <table id="CALCULATION" title="returnableObjects/IntermediateResultsJB/IntermediateResultJB/resultSetName(this should be read in)" columnCount="3" seqNo="1">
                Thanks again,
                Pavan

                Edited by: EJP on 23/05/2012 10:50
                • 5. Re: XSLT Transformation - using variables in title name
                  EJP
                  So I want to use the 1 XSLT above to read in the title name dynamically by using something like "returnableObjects/IntermediateResultsJB/IntermediateResultJB/resultSetName".
                  That's almost exactly how you do it:
                  title="{//returnableObjects/IntermediateResultsJB/IntermediateResultJB/resultSetName}"
                  If that doesn't work you will have to do something like this:
                  <table id="CALCULATION" title="ResultSetName1" columnCount="3" seqNo="1">
                    <xsl:attribute name="title"><xsl:value-of select="//returnableObjects/IntermediateResultsJB/IntermediateResultJB/resultSetName"/></xsl:attribute>
                  ...
                  </table>
                  • 6. Re: XSLT Transformation - using variables in title name
                    868211
                    Thanks!! Yes it did work. Was this a very basic question? I guess my google-fu isnt the best!
                    • 7. Re: XSLT Transformation - using variables in title name
                      EJP
                      You need to get very familiar with XPath and XSLT. I always have both those links open when I'm doing XSLT.

                      Did the first one work? It's really just a shorthand for the second one, but I'm hazy about when {} does and doesn't work in a literal.