-1

What I am trying to do is to transform Global Weather GetCitiesByCountry Web Service XML to CSV.

I have XML:

<string xmlns="http://www.webserviceX.NET">
    <NewDataSet>
        <Table>
            <Country>Canada</Country>
            <City>Quaqtaq Airport</City>
        </Table>
        <Table>
            <Country>Canada</Country>
            <City>Hudson Bay, Sask.</City>
        </Table>

and so on, and XSL:

<?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" version="1.0" encoding="UTF-8" indent="no"/>
  <xsl:template match="/">
    <xsl:for-each select="string/NewDataSet/Table">
      <xsl:value-of select="Country"/>
      <xsl:text>;</xsl:text>
      <xsl:value-of select="City"/>
      <xsl:text>&#13;&#10;</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

but can't manage to make form like this:

Canada;Quaqtaq Airport
Canada;Hudson Bay, Sask.

This XSL makes only XML header, no more data.

EDIT:

So the answer is the coding of the file. The codepage was moving between UTF-8 and UTF-16. I had simply to change string "UTF-16" to "UTF-8" in XML or change the codepage of the file.

I've used the same XSL.

pbies
  • 666
  • 11
  • 28
  • 1
    Before everything, you have a *namespace* issue. See, for example: http://stackoverflow.com/questions/26085859/need-help-in-creating-xslt-i-do-have-source-and-target-xml/26086154#26086154 – michael.hor257k Apr 10 '15 at 09:46
  • This didn't helped me much. Still no result. – pbies Apr 10 '15 at 10:33
  • "*Still no result.*" Post your **modified** stylesheet. – michael.hor257k Apr 10 '15 at 10:55
  • If you know the solution, just post it. – pbies Apr 10 '15 at 11:21
  • @pbies: Rather than insist on being spoon fed the answer in the form you want, read Michael's [previous answer](http://stackoverflow.com/questions/26085859/need-help-in-creating-xslt-i-do-have-source-and-target-xml/26086154#26086154). It applies to your situation (although the question may not really be a duplicate in the conventional sense); understanding Michael's answer there is essential in working in this general area and fixing your particular problem. Thanks. – kjhughes Apr 10 '15 at 11:56
  • I've just added '@' to the front of field names and it didn't changed anything as I stated before. – pbies Apr 10 '15 at 12:05
  • @kjhughes "*the question may not really be a duplicate in the conventional sense*' I've been criticized just [a short while ago](http://stackoverflow.com/questions/29206690/cannot-transform-xml-using-xslt-due-to-namespaces-xmlns/29207337#comment46629824_29206690) for **not** allowing a similar question to be closed. In the present case, I see no such special circumstances. – michael.hor257k Apr 10 '15 at 12:30
  • @pbies `@` is not a namespace prefix. You may read the answer [here](http://stackoverflow.com/questions/29206690/cannot-transform-xml-using-xslt-due-to-namespaces-xmlns/29207337#comment46629824_29206690) in addition to the one I already pointed to. Or do a search. – michael.hor257k Apr 10 '15 at 12:44
  • The difference is that here due to the title, future readers will likely arrive wanting to know about XML to CSV conversion (to which there are many better duplicate questions to refer them) than namespace problems. But this is a minor quibble. Your apropos reference would have helped OP had he/she cared more about understanding than being fed quick fixes. – kjhughes Apr 10 '15 at 12:45
  • Ok, so the problem was the codepage of the file, had to rename UTF-16 in XML file to UTF-8 as this was the format of the file. I can't add answer, but the codepage is the solution. – pbies Apr 16 '15 at 07:27

1 Answers1

-1

Just remove the namespace xmlns="http://www.webserviceX.NET" from the input as pbies mentioned or Try this

<?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" indent="no"/>
  <xsl:template match="/">
    <xsl:message select="//string/."/>
    <xsl:for-each select="*:string/*:NewDataSet/*:Table">
      <xsl:message select="name()"/>
      <xsl:value-of select="*:Country"/>
      <xsl:text>;</xsl:text>
      <xsl:value-of select="*:City"/>
      <xsl:text>&#13;&#10;</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
Bala
  • 68
  • 10