"Andrew C.R. Martin" wrote:
>
> Dear all,
>
> I'm not really sure if this is a Sablotron problem or a general XSLT problem,
> being quite new to both. Any help would be appreciated!
>
> I'm trying to generate SQL from XML using XSLT in text output mode
>
> For example:
>
> <reference ID="5">
> <year>1990</year>
> <authors>Rodrigues NR et al.</authors>
> <title>
> p53 mutations in colorectal cancer
> </title>
> <journal vol="6" first_page="7555" last_page="7559">
> Proc Natl Acad Sci U S A
> </journal>
> <keywords>
> RNA Neoplasm, Protein p53
> </keywords>
> </reference>
>
> If I use a simple template to match the <reference> tags:
>
> <xsl:template match="reference">
> insert into references(id, authors, title, year)
> values (<xsl:value-of select="./@ID"/>,
> '<xsl:value-of select="authors"/>',
> '<xsl:value-of select="title"/>',
> <xsl:value-of select="year"/>);
> </xsl:template>
>
> then my output looks like:
>
> insert into references(id, authors, title, year)
> values (5, 'Rodrigues NR et al.',
> '
> p53 mutations in colorectal cancer
> ',
> 1990);
>
> In other words in lines like the <authors> one where the tags are immediately
> around the data, everything is fine, but in lines like the <title>, the
> newlines and indentation are carried across to the text output.
>
> Is there any way to suppress this behaviour, or some clever trick with substr()
> and translate() to remove leading and trailing white-space and returns?
Your best bet is to wrap literal text in <xsl:text>insert
into...</xsl:text> constructs. If all your literals are wrapped that
way (use 
 to get a newline) you should be OK. If you still find
the processor is adding newlines, you may need to say:
<xsl:template match="whatever"
><xsl:text>insert into references</xsl:text
></xsl:template>
You can also use xsl:strip-space to good effect, but that isn't safe if
you have mixed content models.
Steve