dom
dom

Reputation: 356

How to pass information from xslt to mysql

i need to know how to link my xsl transformation to my database i currently have it set up doing a html conversion but need to insert the data into a database the xslt is a single file only used for conversion and is run in a php script, i saw a thread on it a few days ago but forgot to save it and now cant for the life of me find anything on this. the xml is a feed not a file this is what the xsl looks like:

<?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:variable name="ref" select="lr_rates/hoel_ref"/>
     <xsl:for-each select="//room">
      <xsl:variable name="ref" select="ref"/>
      <xsl:variable name="type" select="type_description"/>
      <xsl:variable name="descr" select="description"/>
      <xsl:variable name="avail" select="rooms_available"/>
      <xsl:variable name="rate" select="rack_rate"/>
      <xsl:variable name="cur" select="rate/requested_currency"/>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

then this is what the database request might look like

 "DELETE FROM `pt_rooms` WHERE hotel_ref = '$id'";
 "INSERT INTO `pt_rooms`(hotel_ref,room_ref,room_type,description,availability,price,currency) VALUES ('$id','$ref','$type','$descr','$avail','$rate','$cur')";

i think i would probably need a mysql_connect statement as-well as its not an application just a singl xsl in a php script if anyone could link to a good explanation

Upvotes: 0

Views: 1244

Answers (1)

Deathspike
Deathspike

Reputation: 8770

XSLT is a XML Transformation, meaning you convert any XML file from XML to any other text-based format that you can come up with. It doesn't magically interact with your database without having some kind of processing code that takes the result and executes the queries. Since you need this and mentioned PHP, you would be better of processing the XML in PHP in the first place and populate the database that way.

Upvotes: 1

Related Questions