'Web-based XML to Text File
I have an XML file that lives on an internal IP address and is regularly updated:
<DATA>
<HEADLINE>
<TEXT>Headline 1</TEXT>
</HEADLINE>
<HEADLINE>
<TEXT>Headline 2</TEXT>
</HEADLINE>
<HEADLINE>
<TEXT>Headline 3</TEXT>
</HEADLINE>
</DATA>
etc for anywhere from 5-15 headlines. I would like to spit this out to a .txt file formatted
Headline 1
Headline 2
Headline 3
etc.
It seems like XSLT would work, but I'm having difficulty telling a script to pull it from the web address (which is static: http://10.2.1.11/cgi-bin/ExportHeadlines.pl). Is there a better way to create this .txt file?
Solution 1:[1]
For the .txt file output you can specify the target format in your XSL stylesheet
<xsl:output method="text" media-type="text/plain" omit-xml-declaration="yes" indent="no"/>
To load the XML document over HTTP you can use the document function
<xsl:template match="/">
<xsl:value-of select="document('http://10.2.1.11/cgi-bin/ExportHeadlines.pl')/DATA"/>
</xsl:template>
Since the source file is regularly updated, you need some kind of scheduler that executes the XSL transformation on a regular base.
Probably you also must provide an input XML file (that you don't use because you load your data inside the XSL stylesheet). Just use a pseudo file to make it happy.
<?xml version="1.0" encoding="UTF-8"?>
<test/>
Alternative: Download first
You can of course also pull the XML data with curl or a similar tool in a first step and then do a plain vanilla XSL transformation with the downloaded XML data file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | burki |
