I'm trying to use this module to get some data out of one big XML-file. I have some problems getting started, some example xsl-file would be helpful. Currently I just get a error message when I try to read a title, it says: "SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'title' at row 1"

Here is my very simple xsl-file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" encoding="UTF-8"/>

  <xsl:template match="/npexchange">
    <xsl:value-of select="article/article_type_id"/>
  </xsl:template>
</xsl:stylesheet>

In the xml-file I have just one line of text for the title, so it shouldn't be a problem:

<article_type_id id="634">Drupal_export</article_type_id>

Comments

znerol’s picture

I confess, documentation for this module is badly needed. I'll briefly outline the process of writing XSLT stylesheets for this module.

First off, I recommend to test your stylesheets before trying to run them from drupal. If you are on a mac or linux you may try the following command line:

xsltproc my-stylesheet.xslt my-data.xml

You will find some interesting GUI tools by searching the web for "XSLT debugger".

You need one stylesheet per field you want to import. E.g. one for the node-title and one for the body. If you have only one record/article/node per xml file, the stylesheets are fairly easy:

title.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="UTF-8"/>
  <xsl:template match="/">
    <xsl:value-of select="//title-element"/>
  </xsl:template>

</xsl:stylesheet>

body.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="UTF-8"/>

  <xsl:template match="/">
    <xsl:value-of select="//body-element"/>
  </xsl:template>

</xsl:stylesheet>

I recommend to use the output method text. You almost certainly do not want any XML in your title-field.

If you have more than one record/article/node per xml file, you may supply a special stylesheet named _count.xslt. When applied to the source file, the count-stylesheet should return the number of records contained.

_count.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="UTF-8"/>

  <xsl:template match="/">
    <xsl:value-of select="count(//body-element)"/>
  </xsl:template>

</xsl:stylesheet>

Then the other stylesheets will be applied to the source documents n times, with a parameter set to the current pass:

body.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="_pass"/>
<xsl:output method="text" encoding="UTF-8"/>

  <xsl:template match="/">
    <xsl:value-of select="//body-element[number($_pass)]"/>
  </xsl:template>

</xsl:stylesheet>

Please refer to the XSLT and XPath specifications for information on how to design XSLT stylesheets:

mbuechner’s picture

Issue summary: View changes

I tried to reproduce this, but Drupal is telling me that 'No pipelines found in XSLT pipeline path.' I'm not sure what I'm doing wrong!? Can anyone provide an easy example of the XSLT pipelines with directory structure, file names and their content? That would really help me! (y)