Namespace stripper in EMML and Transform Node structure for dynamic view

mystic
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 02/22/2011
Points: 20

Hello Mashers,

I have two questions:

1) I am trying to use the namespace stripper using the xsl in EMML

  <xslt script="nsStrip.xsl" wires_id="NamespaceStripper_7" wires_type="NamespaceStripper" inputvariable="assign_3_out" outputvariable="output_0" />

but when i try this code i get an error in the EMML, i think either i need to load this nsStrip.xsl, if yes then from where can i load the nsStrip.xsl and to which place? (this code is from the view EMML in the wires)

2) I am trying to do a transformation from

<Car>

<Color>Blue</Color>

<Brand>Toyota</Brand>

</Car>

 

To

<Properties>

<Property name="Color" value="Blue"\>

<Property name="Brand" value="Toyota"\>

</Properties>

What should i use in EMML to do this transformation, i need to parse through each Car, i was trying

<foreach variable="item" items="$car">
    <appendresult outputvariable="output">
      <Properties>
        <name>{$item}</name>
        <value></value>
      </Properties>
    </appendresult>
    </foreach>

Not sure how to parse child node of Parent node Car and do the transformation, Can <xsl> be used? if yes, can you provide link to an example? Any help will be appreciated.

The thing is input may not always be same type (it can be car, bus, cycle) so i just want to transform to generic node so that Property View can be selected for all in the Mashup (Dynamic view type).

Thanks in advance.

Anjali

 

 

 

 

0
Your rating: None
raj
raj's picture
User offline. Last seen 3 weeks 4 days ago. Offline
Joined: 09/22/2008
Points: 4

 hi Anjali,

 

#1.  nsStrip.xsl is in presto classpath (webapps/presto/WEB-INF/classes).  what's the specific error message you are seeing ?

 

 

#2. If the input is fairly homogeous , u can transform in EMML :

 

<output name='result' type='document' >

   <Properties/>

   </output>  

   

   

 <variable name="cars" type="document">

  <Cars> 

     <Car>

       <Color>Blue</Color>

       <Brand>Toyota</Brand>

    </Car>

     <Car>

       <Color>Red</Color>

       <Brand>Honda</Brand>

    </Car>

     <Car>

       <Color>Green</Color>

       <Brand>Ford</Brand>

    </Car>

     <Bus>

       <Color>Black</Color>

       <Brand>Volvo</Brand>

    </Bus> 

   </Cars> 

  </variable>

 

   

   <foreach variable="item" items="$cars//(Car|Bus)">

         

          <appendresult outputvariable="result">

            <Property name="{$item/Brand/string()}"   color="{$item/Color/string()}"/> 

     </appendresult>

     

   </foreach>

 

For a more complex/varied input XSLT solution seems right. Let us know.

raj.  chief masher @ jackbe

mystic
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 02/22/2011
Points: 20

Hello Raj

Thanks for the reply

1) If i don't specify the whole path, then i get NullPointerException, even if i specify the path to xsl, then i get error for xsl not found, can you give an example of namespace stripper in EMML

2) Actually, here i am trying to capture the attribute name as well along with value,

In the example above,

<Car>

       <Color>Green</Color>

       <Brand>Ford</Brand>

    </Car>

     <Bus>

       <Color>Black</Color>

       <Brand>Volvo</Brand>

    </Bus>

Here Car and Bus may not have same attribute names like Color and Brand, so want to also append the attribute name along with value in the final output, in the solution you gave, i get only the value output ("Black" and "Volvo") in this case,  how can i store the output like

<Property name="<Attribute Name>" value="<Attribute Value>"/>

Here Attribute Name is not known in advance and is known only after parsing the result.

Thanks

Anjali

raj
raj's picture
User offline. Last seen 3 weeks 4 days ago. Offline
Joined: 09/22/2008
Points: 4

 #1 can u try following snippet in your mashup editor environment. This should have stripped off namespaces from atom feed.




<directinvoke endpoint="http://planetjdk.org/feed.atom-1.0" feedtype="atom" outputvariable="feed1"/>   

      

<xslt script="nsStrip.xsl" inputvariable="feed1" outputvariable="result" />

 

 

 

#2  See if this transformation helps...

 

 <variable name="cars" type="document">

   <Cars> 

      <Car>

        <Color>Blue</Color>

        <Brand>Toyota</Brand>

     </Car>

      <Car>

        <Color>Red</Color>

        <Brand>Honda</Brand>

     </Car>

      <Car>

        <Color>Green</Color>

        <Brand>Ford</Brand>

     </Car>

      <Bus>

        <Color>Black</Color>

        <Brand>Volvo</Brand>

     </Bus> 

    </Cars> 

   </variable>

 

    

    <foreach variable="item" items="$cars//(Car|Bus)">

      

       <variable name="prop" type="document">

          <Property/>

       </variable>

      

      <foreach variable="subelem" items="$item/*" >

            <annotate variable="prop" expr=".">

              attribute {name($subelem)} {data($subelem) }

        </annotate>

      </foreach>

      

      <appendresult outputvariable="result">

        <result>{$prop}</result>

      </appendresult>

 

    </foreach>

    

    <constructor outputvariable="result">

      <Properties>{$result//Property}</Properties>

    </constructor>

raj.  chief masher @ jackbe

raj
raj's picture
User offline. Last seen 3 weeks 4 days ago. Offline
Joined: 09/22/2008
Points: 4

 #1 if u still experience error , please paste the stack trace error from prestoserver.log 

#2 the output for this transformation would be:

<Properties>
<Property Brand="Toyota" Color="Blue"/>
<Property Brand="Honda" Color="Red"/>
<Property Brand="Ford" Color="Green"/>
<Property Brand="Volvo" Color="Black"/>
</Properties>

 

raj.  chief masher @ jackbe

mystic
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 02/22/2011
Points: 20

Hello Raj

Thanks for the reply

1) Still having trouble with namespace stripper, i am getting

Error: Error execution Mashup Script :
java.lang.NullPointerException[Line#8] <Whole script>

this error, and no other stack trace, the error is not clear as

Line#8 is::  <output name="output" output-encoding="UTF-8" type="document" wires_id="output"/>

In short error it is pointing to whole script, which is weird, as if i don't use the namespace stripper, i am getting perfect output, but with namespaces attached.

Also, i am using shared Presto, and don't have presto installed on my desktop, so i am not sure where to look for prestoserver.log file, can you point where should i look for this file?

The usage of namespace stripper is as following in my case:

XML node result with namespaces -> namespace stripper -> Parse through the XML nodes to display the contents (in the form <Property name="" value=""\>)

(if i don't use the namespace stripper, i am getting perfect output, but with namespaces attached.)

2) Thanks again, for the help but i used a short version as follows:

<foreach variable="item" items="$cars/*">
   <foreach variable="subitem" items="$item/*">
      <appendresult outputvariable="output">
         <Property name="{name($subitem)}" value="{data($subitem)}"/>
      </appendresult>
   </foreach>
</foreach>

 

Thanks

Anjali

mystic
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 02/22/2011
Points: 20

Just an update:

1) I was writing EMML from scratch, and didn't had any presto meta-data, if i use the template created via wires, and edit it in EMML, then i am able to use XSL for namespace stripper successfully

so the question is what minimum things are required to use xsl: namespace stripper successfully.

Thanks

Anjali

smitchell
smitchell's picture
User offline. Last seen 2 weeks 5 days ago. Offline
Joined: 08/29/2008
Points: 34

The presto-meta tags are specific to Wires and are not required to use the <xslt> statement in a mashup script. The only requirement is to have the XSLT stylesheet located in the classpath (and that is already handled since this XSLT is installed that way) and use the <xslt> statement. Since this is working from Wires, the stylesheet is obviously already in the right location.

The location of the log file depends on the application server hosting Presto. If this is hosted in Tomcat (the default), then you can find it on the computer where Presto is running in {install-dir}/appserver/logs folder. The default location would be Presto3.1/appserver/logs/prestoserver.log.

If it's running on a different app server, check the documentation for that app server. It should be in the same location as other logs.

Sara, technical writer/jackbe

 

raj
raj's picture
User offline. Last seen 3 weeks 4 days ago. Offline
Joined: 09/22/2008
Points: 4

 Hi Anjali,

Regarding #2, looks great !

raj.  chief masher @ jackbe

mystic
User offline. Last seen 1 year 8 weeks ago. Offline
Joined: 02/22/2011
Points: 20

Thanks Sara, information is helpful.

Regards

Anjali