• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Remove xml declarations when using xslt

New Here ,
Oct 15, 2009 Oct 15, 2009

Copy link to clipboard

Copied

Hi, i have created an xslt which transforms an xml file and then imports the information into a mysql database. It works and imports the information into the database but it also brings across the xml delcarations and the node names.

Is there a coldfusion way to remove these declarations, all i want is the information itself brought into the database.

Thanks

Chris

TOPICS
Advanced techniques

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 19, 2009 Oct 19, 2009

Copy link to clipboard

Copied

G'day

One doesn't do it via CF, one does it via the XSLT itself.

Have a read of this: http://www.w3schools.com/xsl/el_output.asp

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2009 Oct 19, 2009

Copy link to clipboard

Copied

Hi Adam,

thanks for the reply. I did go to the site and tried using that option but its still including the declarations, could it be a configuration problem?

Thanks, Chris.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 19, 2009 Oct 19, 2009

Copy link to clipboard

Copied

That's weird, cos it works for me.

Can you post a brief code block (with sample XML and XSL) that demonstrates it not working?  I'll have a look (although perhaps not until tomorrow now, as I've about done my dash for these forums for the day).

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2009 Oct 19, 2009

Copy link to clipboard

Copied

Hi Adam,

here is the code from the xsl file:

<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="data/itemfeed.xml" --><!DOCTYPE xsl:stylesheet  [
    <!ENTITY nbsp  "&#160;">
    <!ENTITY copy  "&#169;">
    <!ENTITY reg    "&#174;">
    <!ENTITY trade  "&#8482;">
    <!ENTITY mdash  "&#8212;">
    <!ENTITY ldquo  "&#8220;">
    <!ENTITY rdquo  "&#8221;">
    <!ENTITY pound  "&#163;">
    <!ENTITY yen    "&#165;">
    <!ENTITY euro  "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<body>
<xsl:for-each select="Items/Item[ItemType='Standard']">
<xsl:value-of select="EANNumber"/>

</xsl:for-each>
</body>
</html>

</xsl:template>
</xsl:stylesheet>

And here is some sample data from the XML file:

<?xml version="1.0" encoding="UTF-8" ?>
<Items>
    <Item>
        <ItemType>Standard</ItemType>
        <EANNumber>111222333444</EANNumber>
    </Item>
</Items>

Thanks alot, i appreciate the help.

Chris

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2009 Oct 21, 2009

Copy link to clipboard

Copied

Ah, OK I see what you mean.  I think.

Your problem is that you're telling it to put all that extraneous stuff in there.

When I run your code, the result is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>111222333444</body></html>

I presume you are only wanting this:

111222333444

If that's the case, get rid of all the doctype/html/head/body crap form your XSL.  If you don't want it, don't put it in there!

Or are we talking @ cross-purposes here?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2009 Oct 22, 2009

Copy link to clipboard

Copied

Hi Adam,

the HTML, Body tags etc are fine, they can stay, its the actual tags that surround the results that i want to get rid of. When i look at the source code, the results show up like this: <?xml version="1.0" encoding="UTF-8"?><EANNumber>111222333444</EANNumber>. I only want the 111222333444, i dont want the surrounding tags.

Thanks

Chris

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2009 Oct 22, 2009

Copy link to clipboard

Copied

LATEST

Right.

Well I think you better post your actual code in its entirety then.  Because when I slap <cfxml> tags around each of the XSL and XML you provide, and do an xmlTransForm() on them, I just get the numbers (and all the other HTML crap), but no <EANNumber> tags. I get *exactly* what I posted before.

My code is thus:

<cfxml variable="xXsl">

[YOUR XSL HERE]

</cfxml>

<cfxml variable="xXml">

[YOUR XML HERE]

</cfxml>
<cfoutput>#xmlTransform(xXml, xXsl)#</cfoutput>

That outputs what I cited above.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation