Topic
7 replies Latest Post - ‏2013-08-05T21:23:47Z by mtz
mtz
mtz
38 Posts
ACCEPTED ANSWER

Pinned topic XSLT issue while using Eclipse IDE

‏2013-07-19T17:03:01Z |

Hi, 

I am trying to run an xslt using eclipe IDE (and testing the output directly by running against xslt coproc on Datapower). Its a basic xml file with very simple xslt. PFB both alongwith the output that I am getting:

XML:

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet href="NewStylesheet.xsl" type="text/xsl"?>

<soadp>
<names>
  <names1>
    <name>sfdf</name>
    <role>122</role>
  </names1>
  <names1>
    <name>sfdfa</name>
    <role>1223</role>
  </names1>
</names>
<names2>
  <names111>
    <name11>sfdf</name11>
    <emp>12222</emp>
  </names111>
  <names111>
    <name11>sfdfa</name11>
    <emp>1222234</emp>
  </names111>
</names2>
</soadp> 

 

xslt: 

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
 
<xsl:for-each select="soadp/names/names1">
Name:
<xsl:value-of select="name"/>
 
role:
<xsl:value-of select="role"/>
 
empID:
<xsl:call-template name="hello">
<xsl:with-param name="hi" select="name"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
 
<xsl:template name="hello">
<xsl:param name="hi"/>
 
<xsl:for-each select="soadp/names2/names111">
<wow>heee</wow>
<xsl:if test="name11=$hi">
<xsl:value-of select="emp"/>
</xsl:if>
 
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

 

Output:

 

 
Name:
sfdf
 
role:
122
 
empID:
 
Name:
sfdfa
 
role:
1223
 
empID:

 

Here in the output I am not getting the value for empID field which has to come using call-template but I am observing that template call is not happening only. Is it something related to coproc while we run from eclipse directly or is there an issue with stylesheet. 

I have seen this issue earlier also so would be helpful if someone could help me debug it!!

  • HermannSW
    HermannSW
    3147 Posts
    ACCEPTED ANSWER

    Re: XSLT issue while using Eclipse IDE

    ‏2013-07-19T17:58:27Z  in response to mtz

    In case of doubt, run another XSLT processor.

    If the output is the same, then most likely the stylesheet has a problem.

    Here xsltproc generates the same output:

    $ xsltproc mtz.xsl mtz.xml
    <?xml version="1.0"?>

    Name:
    sfdf
     
    role:
    122
     
    empID:

    Name:
    sfdfa
     
    role:
    1223
     
    empID:

    $


    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

     

     

  • Miel
    Miel
    49 Posts
    ACCEPTED ANSWER

    Re: XSLT issue while using Eclipse IDE

    ‏2013-07-19T20:05:01Z  in response to mtz

    Hi,

                  Your xpath for the <xsl:for-each> which is present inside the <xsl:template name="hello"> is wrong .that's the issue .In that, xpath should start with '/' because since there is no match for this template. Try with the below code.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     
    <xsl:template match="/">
    <xsl:for-each select="soadp/names/names1">
    Name:
    <xsl:value-of select="name"/>
     
     role:
    <xsl:value-of select="role"/>
     
    empID:
    <xsl:call-template name="hello">
    <xsl:with-param name="hi">
    <xsl:value-of select="name"/>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:for-each>
    </xsl:template>
    <xsl:template name="hello">
    <xsl:param name="hi"/>
    <xsl:for-each select="/soadp/names2/names111">
     
    <xsl:if test="name11=$hi">
    <xsl:value-of select="emp"/>
    </xsl:if>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
     

    Regards,

    Miel

    • mtz
      mtz
      38 Posts
      ACCEPTED ANSWER

      Re: XSLT issue while using Eclipse IDE

      ‏2013-07-20T11:41:17Z  in response to Miel

      Hi Miel,

      It worked; didn't notice for so long that root was missing .Thanks a ton really!

      • HermannSW
        HermannSW
        3147 Posts
        ACCEPTED ANSWER

        Re: XSLT issue while using Eclipse IDE

        ‏2013-07-20T12:29:19Z  in response to mtz

        Hi,

        assuming that the "<wow>heee</wow>" was inserted by you for debugging only,

        you might want to remove the (procedural) "<xsl:for-each ...><xsl:if  >...</xsl:if></xsl:for-each>" pattern.

        This diff shows how you can collapse the template to just a single statement doing the same:

        $ diff mtz.xsl mtz.2.xsl
        22,28c22
        < <xsl:for-each select="/soadp/names2/names111">
        < <wow>heee</wow>
        < <xsl:if test="name11=$hi">
        < <xsl:value-of select="emp"/>
        < </xsl:if>
        <  
        < </xsl:for-each>
        ---
        > <xsl:value-of select="/soadp/names2/names111[name11=$hi]/emp"/>
        $

         

        Btw, since this new forum software does not allow for {code}...{code} sections, I did a two step approach to get above:

        1. select code and Blockquote it (the icon after "Decrease indent")
        2. while still selected, change font to Courier New (monospaced font)

        Not perfect, but seems to be the best we can get ...


        Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

         

        • mtz
          mtz
          38 Posts
          ACCEPTED ANSWER

          Re: XSLT issue while using Eclipse IDE

          ‏2013-08-03T11:50:10Z  in response to HermannSW

          Hi Hermann,

          Sorry for delayed reply but checked this post just now, yeah this one-liner is really good. But again I am stuck at something; what I am trying to do is fetch domain status using soma and generate a list of all those domains where either probe is ON or debug log is enabled. PFB the xml (omitted) and xslt:

          XML:

           

          <?xml version="1.0" encoding="UTF-8"?>
          <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
          <env:Body>
          <dp:response xmlns:dp="http://www.datapower.com/schemas/management">
          <dp:timestamp>2013-08-03T08:10:21Z</dp:timestamp>
          <dp:status>
          <DomainStatus xmlns:env="http://www.w3.org/2003/05/soap-envelope">
          <Domain>hello</Domain>
          <SaveNeeded>off</SaveNeeded>
          <TraceEnabled>off</TraceEnabled>
          <DebugEnabled>off</DebugEnabled>
          <ProbeEnabled>off</ProbeEnabled>
          <DiagEnabled>off</DiagEnabled>
          <CurrentCommand/>
          <QuiesceState/>
          </DomainStatus>
          <DomainStatus xmlns:env="http://www.w3.org/2003/05/soap-envelope">
          <Domain>hello1</Domain>
          <SaveNeeded>off</SaveNeeded>
          <TraceEnabled>off</TraceEnabled>
          <DebugEnabled>off</DebugEnabled>
          <ProbeEnabled>off</ProbeEnabled>
          <DiagEnabled>off</DiagEnabled>
          <CurrentCommand/>
          <QuiesceState/>
          </DomainStatus>
          </dp:status>
          </dp:response>
          </env:Body>
          </env:Envelope>

           

          XSLT:

           

          <?xml version="1.0" encoding="UTF-8"?>
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="/">
          <xsl:for-each select="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='response']/*[local-name()='status']/DomainStatus">
          <xsl:if test="DebugEnabled='on' | ProbeEnabled='on'">
          <DomainDetails>
          <xsl:value-of select = "Domain"/>
          <xsl:value-of select = "DebugEnabled"/>
          <xsl:value-of select = "ProbeEnabled"/>
          </DomainDetails>
          </xsl:if>
          </xsl:for-each>
          </xsl:template>
          </xsl:stylesheet>

          I am getting the error in probe as:

            'coproc://uncacheable//D:/Xan/IBMDP%20Workspace/probe/probe_log.xsl:5: type of the left-hand side of / operator must be a nodeset, but isn't'

           The stylesheet is compiling successfully but this error is happening while doing transformation. Could you check why is it so? Guess here also I could use one-line in place if / for-each but I want to make sure it gives me the desired output both the ways. 

          • HermannSW
            HermannSW
            3147 Posts
            ACCEPTED ANSWER

            Re: XSLT issue while using Eclipse IDE

            ‏2013-08-03T19:17:40Z  in response to mtz

            Hi  Mohit,

            the "|" XPath operator expects nodesets, but in your expression left and right hand side are both booleans.

            This simple diff makes it work, I changed your sample input as well to see that the modified stylesheet does what you want.

            What you need to know is, that if you compare a node-set and a string (as in Mohit.2.xsl), it is true if and only if the string is equal to at least one node.
            As you can see below I did run on DataPower XSLT processor, as well as on xsltproc and Saxon 6.5.5 (the last XSLT 1.0 XSLT processor).

            $ diff Mohit.xsl Mohit.2.xsl
            5c5
            < <xsl:if test="DebugEnabled='on' | ProbeEnabled='on'">
            ---
            > <xsl:if test="(DebugEnabled | ProbeEnabled)='on'">
            $
            $ diff Mohit.xml Mohit.2.xml
            11c11
            < <DebugEnabled>off</DebugEnabled>
            ---
            > <DebugEnabled>on</DebugEnabled>
            22c22
            < <ProbeEnabled>off</ProbeEnabled>
            ---
            > <ProbeEnabled>on</ProbeEnabled>
            $
            $ coproc2 Mohit.2.xsl Mohit.2.xml http://dp1-l3:2223 ; echo
            <?xml version="1.0" encoding="UTF-8"?>
            <DomainDetails>helloonoff</DomainDetails><DomainDetails>hello1offon</DomainDetails>
            $
            $ xsltproc Mohit.2.xsl Mohit.2.xml
            <?xml version="1.0"?>
            <DomainDetails>helloonoff</DomainDetails><DomainDetails>hello1offon</DomainDetails>
            $
            $ java -jar ~/Desktop/saxon6-5-5/saxon.jar Mohit.2.xml Mohit.2.xsl ; echo
            <?xml version="1.0" encoding="utf-8"?><DomainDetails>helloonoff</DomainDetails><DomainDetails>hello1offon</DomainDetails>
            $

             

            Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

            Updated on 2013-08-03T19:20:21Z at 2013-08-03T19:20:21Z by HermannSW
            • mtz
              mtz
              38 Posts
              ACCEPTED ANSWER

              Re: XSLT issue while using Eclipse IDE

              ‏2013-08-05T21:23:47Z  in response to HermannSW

              Got it Hermann. Thanks a lot!! could you tell if I could this compare tool which uses diff?