Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
13 replies Latest Post - ‏2011-08-26T14:52:05Z by Liv2luv
lucaamato
lucaamato
6 Posts
ACCEPTED ANSWER

Pinned topic How to manage ’ &egrave in XSL datapower tranformation

‏2011-08-23T20:33:14Z |
The received xml I need to retrieve the following data node:

Il ritratto, che accoglie i visitatori all'ingresso della casa-museo, era stato commissionato dalla madre di Gian Giacomo, Rosina Trivulzio. Il giovane Poldi Pezzoli, in questa immagine ufficiale, è
...
...


When I extract data with xsl code like the following :
.
.

<xsl:template match="div">
<fieldBody><xsl:value-of select="."/></fieldBody>
</xsl:template>
.
.

the retruned data node is truncated in the ' tag as the following
.
.
.
<fieldBody>
In passato il dipinto era stato datato al 1846-1848 circa, una datazione suggerita dalla foggia dellrsquo
</fieldBody>
.
.

In the head of XSL declaration I use the following encoding declaration.

<xsl:output method="xml" indent="no" encoding="ISO-8859-1" />

How is the best way to extract in a correct way the node value?

Many thanks in advance

Ciao
Updated on 2011-08-26T14:52:05Z at 2011-08-26T14:52:05Z by Liv2luv
  • HermannSW
    HermannSW
    4487 Posts
    ACCEPTED ANSWER

    Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

    ‏2011-08-23T20:38:21Z  in response to lucaamato
    Hi,

    your posting is hard to read, and the input seems to be scrambled by the Forum SW.

    May you please attach your input XML file?
    This will make answering your question a lot easier than to guess what you might have posted ...

     
    Hermann<myXsltBlog/>
  • lucaamato
    lucaamato
    6 Posts
    ACCEPTED ANSWER

    Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

    ‏2011-08-24T13:02:20Z  in response to lucaamato
    I understand but unfortunately the tag was changed by the html editor

    In attach the input file

    The xsl is not able to process &&rsquo and similar tag.

    Attachments

  • lucaamato
    lucaamato
    6 Posts
    ACCEPTED ANSWER

    Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

    ‏2011-08-24T13:04:42Z  in response to lucaamato
    I use the following XSL processing file. If I test it using editix its works perfetctly...using datapower DP trunk the node infi when the it try to proecess &&rsquo tag
    • HermannSW
      HermannSW
      4487 Posts
      ACCEPTED ANSWER

      Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

      ‏2011-08-24T14:01:57Z  in response to lucaamato
      The problem is simple, your file 412.xml is Non-XML!

      I often use tidy tool to check for XML validity:
      
      $ tidy -q -xml 412.xml >out 2>err $ $ cat err line 22 column 69 - Warning: unescaped & or unknown entity 
      "&nbsp" line 22 column 75 - Warning: unescaped & or unknown entity 
      "&nbsp" line 36 column 17 - Warning: unescaped & or unknown entity 
      "&nbsp" line 36 column 29 - Warning: unescaped & or unknown entity 
      "&nbsp" line 56 column 62 - Warning: unescaped & or unknown entity 
      "&rsquo" line 56 column 223 - Warning: unescaped & or unknown entity 
      "&egrave" line 56 column 322 - Warning: unescaped & or unknown entity 
      "&egrave" line 56 column 486 - Warning: unescaped & or unknown entity 
      "&agrave" line 58 column 101 - Warning: unescaped & or unknown entity 
      "&rsquo" line 58 column 146 - Warning: unescaped & or unknown entity 
      "&agrave" line 58 column 201 - Warning: unescaped & or unknown entity 
      "&rsquo" line 58 column 249 - Warning: unescaped & or unknown entity 
      "&rsquo" line 59 column 26 - Warning: unescaped & or unknown entity 
      "&rsquo" line 59 column 80 - Warning: unescaped & or unknown entity 
      "&ugrave" line 59 column 104 - Warning: unescaped & or unknown entity 
      "&rsquo" line 59 column 132 - Warning: unescaped & or unknown entity 
      "&rsquo" line 59 column 227 - Warning: unescaped & or unknown entity 
      "&rsquo" $ $ cut -f2 -d\
      " err | sort -u &agrave &egrave &nbsp &rsquo &ugrave $
      


      A solution would be to proxy the (Non-XML) input through a "repair" service like here:
      http://www-01.ibm.com/support/docview.wss?uid=swg27019119&aid=1#page=6

      You will have to replace all HTML entities (unknown to XML) by their definition, eg. replace &​agrave; by &​224; ...
      http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML

       
      Hermann<myXsltBlog/>
    • Liv2luv
      Liv2luv
      573 Posts
      ACCEPTED ANSWER

      Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

      ‏2011-08-24T14:34:46Z  in response to lucaamato
      Remove the HTML DocType declaration and add the following doctype declarations in your XML input file:

      <!DOCTYPE mobile_page [
              <!ENTITY nbsp "&amp;nbsp;">
              <!ENTITY rsquo "&amp;rsquo;">
              <!ENTITY egrave "&amp;egrave;">
              <!ENTITY agrave "&amp;agrave;">
              <!ENTITY ugrave "&amp;ugrave;">
      ]>
      


      But this is just a quick way to see this working. There was a WTX map I've posted to remove the <!DOCTYPE ...> declaration. Guess another WTX map may be used to replace all & with & amp;

      Thanks.
      Updated on 2014-03-25T03:12:37Z at 2014-03-25T03:12:37Z by iron-man
      • lucaamato
        lucaamato
        6 Posts
        ACCEPTED ANSWER

        Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

        ‏2011-08-24T19:58:14Z  in response to Liv2luv
        many thanks to all.

        for HermannSW
        I'm agree with you that the &rsquo and similar tags are not totally XML standard, my problem is how to manage it...obviously I can not remove it from source...I need to manage it

        for Liv2luv
        Yes it may be a solution...where I can found a WTX example map to replace <!DOCTYPE declaration?

        Ciao
        • Liv2luv
          Liv2luv
          573 Posts
          ACCEPTED ANSWER

          Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

          ‏2011-08-24T20:08:18Z  in response to lucaamato
          Please search for doctype-remover.dpa in this thread:

          http://www.ibm.com/developerworks/forums/message.jspa?messageID=14627249

          Thanks.
          • HermannSW
            HermannSW
            4487 Posts
            ACCEPTED ANSWER

            Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

            ‏2011-08-24T20:45:10Z  in response to Liv2luv
            Hi Suresh,

            interesting idea to just replace the ampersand character by its entity definition
            (instead of defining each entity like I described).

            If this solution is sufficient, ampify.xsl is an easy soution to it:
            • gets (UTF-8 encoded) Non-XML text (HTML)
            • strips DOCTYPE definition if present
            • replaces all & by &​amp; (resulting in eg. &​amp;agrave; for &​agrave;)
            • the binay output-mapping ensures that & and < do not get esacped(!)
            
            $ cat ampify.xsl <xsl:stylesheet version=
            "1.0" xmlns:xsl=
            "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
            "http://www.datapower.com/extensions" xmlns:regexp=
            "http://exslt.org/regular-expressions" extension-element-prefixes=
            "dp" > <dp:input-mapping   href=
            "store:///pkcs7-convert-input.ffd" type=
            "ffd"/> <dp:output-mapping  href=
            "store:///pkcs7-convert-input.ffd" type=
            "ffd"/>   <xsl:output omit-xml-declaration=
            "yes" /> <xsl:template match=
            "/"> <xsl:variable name=
            "html" select=
            "dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>   <xsl:variable name=
            "htmlwodt"> <xsl:choose> <xsl:when test=
            "starts-with($html,'&lt;!DOCTYPE')"> <xsl:value-of select=
            "substring-after($html,'>')" /> </xsl:when> <xsl:otherwise> <xsl:value-of select=
            "$html"/> </xsl:otherwise> </xsl:choose> </xsl:variable>   <xsl:variable name=
            "xml" select=
            "regexp:replace($htmlwodt,'&amp;','g','&amp;amp;')"/>   <object> <message> <xsl:copy-of select=
            "dp:binary-decode(dp:encode($xml,'base-64'))"/> </message> </object> </xsl:template> </xsl:stylesheet> $
            


             
            Hermann<myXsltBlog/>
            • HermannSW
              HermannSW
              4487 Posts
              ACCEPTED ANSWER

              Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

              ‏2011-08-24T20:52:46Z  in response to HermannSW
              I wanted to use coproc2 client to demonstrate the solution.
              Find attached the nonxml coproc2 service listening on port 2224 (instead 2223 for normal coproc2 service).

              Nice, chaining of binary and normal transform action by sequence of coproc2 calls:
              
              $ coproc2 ampify.xsl 412.xml http:
              //dp3-l3:2224 | \ > coproc2 body2Extract.xsl - http:
              //dp3-l3:2223 <array><blocco>                                   <href>http:
              //www.museopoldipezzoli.it/audioguide/it_Francesco_Hayez_Ritratto_Gian_Giacomo_Poldi_Pezzoli.mp3</href><audioguida> AUDIOGUIDA 110</audioguida> <fieldBody> Il ritratto, che accoglie i visitatori all&amp;rsquo;ingresso della casa-museo, era stato commissionato dalla madre di Gian Giacomo, Rosina Trivulzio. Il giovane Poldi Pezzoli, in questa immagine ufficiale, &amp;egrave; raffigurato in un interno privo di connotazioni spaziali, in cui la parete scura di fondo &amp;egrave; animata soltanto da un riflesso di luce. Raffigurato seduto di tre quarti, con le gambe accavallate, in una posa elegante e disinvolta, guarda con intensit&amp;agrave; verso lo spettatore, con cui stabilisce un rapporto intimo e diretto.   In passato il dipinto era stato datato al 1846-1848 circa, una datazione suggerita dalla foggia dell&amp;rsquo;abito, che sarebbe stato fuori moda gi&amp;agrave; nel 1850. Oggi, invece, si preferisce datare l&amp;rsquo;opera al 1851, anno in cui fu esposta all&amp;rsquo;Accademia di Brera. Evidentemente, il futuro fondatore del Museo, divenuto maggiorenne ed entrato in possesso delle fortune di famiglia, aveva scelto di apparire con un abito nero, serio ed elegante, adatto a un ritratto di rappresentanza. Nei decenni centrali dell&amp;rsquo;Ottocento Francesco Hayez era il ritrattista pi&amp;ugrave; apprezzato dall&amp;rsquo;alta borghesia e dall&amp;rsquo;aristocrazia milanesi, che amavano la sua pittura rigorosa e interiorizzata, attenta all&amp;rsquo;indagine psicologica dei personaggi.   M.B.            Consulta la scheda scientifica   </fieldBody><end></end></blocco></array>$ $
              


               
              Hermann<myXsltBlog/>
            • Liv2luv
              Liv2luv
              573 Posts
              ACCEPTED ANSWER

              Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

              ‏2011-08-24T21:14:21Z  in response to HermannSW
              Your solution is very simple and very good, as always. This should fit for the need to lucaamato.

              Thanks.
              • lucaamato
                lucaamato
                6 Posts
                ACCEPTED ANSWER

                Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

                ‏2011-08-25T16:47:12Z  in response to Liv2luv
                Hy guys...thanks for your solution

                its works, but I need to create 2 different MPG.

                the first call the backend and on the response use ampify.xsl (to remove &) and repair.xsl ( to put oh head the correct xml tag in according to Liv2Luv suggestion)

                the second call the first to obtain the manipulated XML and apply the request transformation (using body2extract.xsl) and so on.

                If I try to use all in the same sequence the body2extract.xsl do not catch the XML file (come from repair.xsl) and the response has in the obtain xml the lt; tag instead <. It is not clear for me way, every time that i used binary transform I don not manipulate the response like a traditional XML. Any suggestion?
                • Liv2luv
                  Liv2luv
                  573 Posts
                  ACCEPTED ANSWER

                  Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

                  ‏2011-08-25T19:01:11Z  in response to lucaamato
                  >I need to create 2 different MPG.
                  Not sure I understand why.

                  If the service chain is necessary only to convert &lt; to <; then you can embed body2extract.xsl into ampify.xsl to get the required output. See attached modified-ampify.xsl which produces output as below:

                  
                  <?xml version=
                  "1.0" encoding=
                  "UTF-8"?> <array><blocco>                                                                                                                                                                                                                                                                                                                                    <href>http:
                  //www.museopoldipezzoli.it/audioguide/it_Francesco_Hayez_Ritratto_Gian_Giacomo_Poldi_Pezzoli.mp3</href><audioguida>                                                    AUDIOGUIDA                 110</audioguida>           <fieldBody>               Il ritratto, che accoglie i visitatori all&amp;rsquo;ingresso della casa-museo, era stato commissionato dalla madre di Gian Giacomo, Rosina Trivulzio. Il giovane Poldi Pezzoli, in questa immagine ufficiale, &amp;egrave; raffigurato in un interno privo di connotazioni spaziali, in cui la parete scura di fondo &amp;egrave; animata soltanto da un riflesso di luce. Raffigurato seduto di tre quarti, con le gambe accavallate, in una posa elegante e disinvolta, guarda con intensit&amp;agrave; verso lo spettatore, con cui stabilisce un rapporto intimo e diretto. In passato il dipinto era stato datato al 1846-1848 circa, una datazione suggerita dalla foggia dell&amp;rsquo;abito, che sarebbe stato fuori moda gi&amp;agrave; nel 1850. Oggi, invece, si preferisce datare l&amp;rsquo;opera al 1851, anno in cui fu esposta all&amp;rsquo;Accademia di Brera. Evidentemente, il futuro fondatore del Museo, divenuto maggiorenne ed entrato in possesso delle fortune di famiglia, aveva scelto di apparire con un abito nero, serio ed elegante, adatto a un ritratto di rappresentanza.Nei decenni centrali dell&amp;rsquo;Ottocento Francesco Hayez era il ritrattista pi&amp;ugrave; apprezzato dall&amp;rsquo;alta borghesia e dall&amp;rsquo;aristocrazia milanesi, che amavano la sua pittura rigorosa e interiorizzata, attenta all&amp;rsquo;indagine psicologica dei personaggi.M.B.                Consulta la scheda scientifica                                                                  </fieldBody><end/></blocco></array>
                  


                  Thanks.
                  • Liv2luv
                    Liv2luv
                    573 Posts
                    ACCEPTED ANSWER

                    Re: How to manage &rsquo; &#38;egrave in XSL datapower tranformation

                    ‏2011-08-26T14:52:05Z  in response to Liv2luv
                    Sorry, I did not attached the modified XSLT with previous post. Here it is now:

                    
                    <xsl:stylesheet version=
                    "1.0" xmlns:xsl=
                    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
                    "http://www.datapower.com/extensions" xmlns:regexp=
                    "http://exslt.org/regular-expressions" xmlns:exsl=
                    "http://exslt.org/common" extension-element-prefixes=
                    "dp" exclude-result-prefixes=
                    "exsl regexp dp"> <dp:input-mapping href=
                    "store:///pkcs7-convert-input.ffd" type=
                    "ffd"/> <!--<dp:output-mapping href=
                    "store:///pkcs7-convert-input.ffd" type=
                    "ffd"/>-->   <xsl:output omit-xml-declaration=
                    "no"/>   <xsl:template match=
                    "/"> <xsl:variable name=
                    "html" select=
                    "dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>   <xsl:variable name=
                    "htmlwodt"> <xsl:choose> <xsl:when test=
                    "starts-with($html,'&lt;!DOCTYPE')"> <xsl:value-of select=
                    "substring-after($html,'>')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select=
                    "$html"/> </xsl:otherwise> </xsl:choose> </xsl:variable>   <xsl:variable name=
                    "xml" select=
                    "regexp:replace($htmlwodt,'&amp;','g','&amp;amp;')"/> <dp:set-variable name=
                    "'var://context/ctx/xml'" value=
                    "dp:parse($xml)"/> <xsl:variable name=
                    "parsedXML" select=
                    "dp:variable('var://context/ctx/xml')"/> <xsl:variable name=
                    "output"> <xsl:apply-templates select=
                    "$parsedXML/mobile_page" mode=
                    "start"/> </xsl:variable> <!-- <dp:set-variable name=
                    "'var://context/ctx/result'" value=
                    "$output"/> <object> <message> <xsl:copy-of select=
                    "dp:binary-decode(dp:encode(exsl:node-set($output),'base-64'))"/> </message> </object>--> <xsl:copy-of select=
                    "$output"/> </xsl:template> <xsl:template match=
                    "mobile_page" mode=
                    "start">   <array> <blocco> <xsl:apply-templates select=
                    "content/div/div"/> <!--xsl:apply-templates select=
                    "content/div/div/div/div/a"/--> <xsl:apply-templates select=
                    "footer"/> </blocco> </array>   </xsl:template> <xsl:template match=
                    "div[@class='views-field-item']"> <!--views-field-item><xsl:value-of select=
                    "."/></views-field-item--> </xsl:template>   <xsl:template match=
                    "div[@id='row']"> <!--row3--> <xsl:apply-templates select=
                    "./div/a"/> <!--/row3--> </xsl:template> <xsl:template match=
                    "a"> <xsl:
                    
                    if test=
                    "../@id = 'row'">   <href> <xsl:value-of select=
                    "@href"/> </href> <audioguida> <xsl:value-of select=
                    "."/> </audioguida>   </xsl:if> </xsl:template>     <xsl:template match=
                    "div[@class='views-field-item-title']"> <!--views-field-item-title><xsl:value-of select=
                    "."/></views-field-item-title--> </xsl:template>   <xsl:template match=
                    "div[@id='fieldBody']"> <fieldBody> <xsl:value-of select=
                    "."/> </fieldBody> </xsl:template>     <xsl:template match=
                    "footer"> <end/> </xsl:template> </xsl:stylesheet>