Getting XML-data using SQL extension

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting XML-data using SQL extension

Mathias Payer
Hi list,

I'm tying to use saxon and the saxon sql extension to transform data
from different db's.

A field in the database contains part of an xml document. I now want to
use this document inside a xsl.

The problem I have is that all < and > are escaped (&lt; and &gt;) and
that I only get a "string". But I want an xml tree.

To demonstrate what I'm doing I'll post a little bit of code:

...
    <xsl:variable name="connection" as="java:java.lang.Object"
xmlns:java="http://saxon.sf.net/java-type">
      <sql:connect driver="{$driver}" database="{$datasource}"
user="{$username}" password="{$password}"/>      
    </xsl:variable>
...
    <xsl:variable name="rs">
      <sql:query connection="$connection" table="aenderungen"
column="src_nr,src_zusatz,dst_artpos,typ,inkraftdatum,gueltig_bis,aenderung" where="{concat('dst_nr=',$singlequote,$lgblnr,$singlequote,' AND dst_zusatz=',$singlequote,$lgblzusatz,$singlequote)}"/>
    </xsl:variable>
   
    <GMGBuch>
      <xsl:for-each select="$rs//row">
        <aenderung typ="{col[4]}" dst_artpos="{col[3]}">
          <source nr="{col[1]}" zusatz="{col[2]}"/>
          <zeitraum inkraftdatum="{col[5]}" gueltig_bis="{col[6]}"/>
          <daten>
            <xsl:copy-of select="col[7]"/>
          </daten>
        </aenderung>
      </xsl:for-each>
    </GMGBuch>

The "xml"-data is in col[7]. How can I use this data as a normal xml
document and not as string?

Any help is appreciated.

Regards,
Mathias

--
Information about me, my projects and contact details:
http://nebelwelt.net

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Getting XML-data using SQL extension

Michael Kay
Try replacing

<xsl:copy-of select="col[7]"/>

with

<xsl:copy-of select="saxon:parse(col[7])"/>

To convert lexical XML into tree form, you need to parse it, which is what
saxon:parse() does.

The other alternative is

<xsl:value-of select="col[7]" disable-output-escaping="yes"/>

which is more suitable if the data isn't well-formed, for example if it's
dirty HTML: but then you need to make sure that the transformation is
serializing its output.

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Mathias Payer
> Sent: 16 March 2006 15:54
> To: [hidden email]
> Subject: [saxon] Getting XML-data using SQL extension
>
> Hi list,
>
> I'm tying to use saxon and the saxon sql extension to transform data
> from different db's.
>
> A field in the database contains part of an xml document. I
> now want to
> use this document inside a xsl.
>
> The problem I have is that all < and > are escaped (&lt; and &gt;) and
> that I only get a "string". But I want an xml tree.
>
> To demonstrate what I'm doing I'll post a little bit of code:
>
> ...
>     <xsl:variable name="connection" as="java:java.lang.Object"
> xmlns:java="http://saxon.sf.net/java-type">
>       <sql:connect driver="{$driver}" database="{$datasource}"
> user="{$username}" password="{$password}"/>      
>     </xsl:variable>
> ...
>     <xsl:variable name="rs">
>       <sql:query connection="$connection" table="aenderungen"
> column="src_nr,src_zusatz,dst_artpos,typ,inkraftdatum,gueltig_
> bis,aenderung"
> where="{concat('dst_nr=',$singlequote,$lgblnr,$singlequote,'
> AND dst_zusatz=',$singlequote,$lgblzusatz,$singlequote)}"/>
>     </xsl:variable>
>    
>     <GMGBuch>
>       <xsl:for-each select="$rs//row">
>         <aenderung typ="{col[4]}" dst_artpos="{col[3]}">
>           <source nr="{col[1]}" zusatz="{col[2]}"/>
>           <zeitraum inkraftdatum="{col[5]}" gueltig_bis="{col[6]}"/>
>           <daten>
>             <xsl:copy-of select="col[7]"/>
>           </daten>
>         </aenderung>
>       </xsl:for-each>
>     </GMGBuch>
>
> The "xml"-data is in col[7]. How can I use this data as a normal xml
> document and not as string?
>
> Any help is appreciated.
>
> Regards,
> Mathias
>
> --
> Information about me, my projects and contact details:
> http://nebelwelt.net
>




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Getting XML-data using SQL extension

Florent Georges
In reply to this post by Mathias Payer
Mathias Payer wrote:

> The "xml"-data is in col[7]. How can I use this data as
> a normal xml document and not as string?

  If I understand well, you have (in 'col[7]') a piece of XML, but as a
string, and want to output it s XML in the result tree.

  I think you have two solutions: either to use the D-O-E attribute of
xsl:value-of, or to use the saxon:parse extension:

    <xsl:copy-of select="saxon:parse(col[7])"/>

  Not tested.

  Regards,

--drkm



       

       
               
___________________________________________________________________________
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help