1 2 3 4 5 6 7 8 9 10 11 12
<root> <element> <foo>1</foo> <bar> <baz>2</baz> <fooz>3</fooz> </bar> </element> <element> <foo>1</foo> </element> </root>
1 2 3 4 5 6 7 8 9 10
<root> <element> <foo>1</foo> <bar.baz>2</bar.baz> <bar.fooz>3</bar.fooz> </element> <element> <foo>1</foo> </element> </root>
considering I am interested in converting each 'element' into a CSV line.
The 'namespaced' element names are required, because they serve as the CSV column headers and they are required to be unique (which, for our case, is guaranteed by this approach).
The other subproblem is converting XML to CSV, of which the main challenge was making sure the last element is not followed by a comma.
In the end, I came up with the templates below to print the values of the 'childless' elements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<xsl:template match="//element"> <xsl:apply-templates select="*" /> <xsl:text>
</xsl:text> </xsl:template> <xsl:template match="//element//*"> <xsl:choose> <xsl:when test="count(child::*) > 0"> <xsl:apply-templates select="*" /> </xsl:when> <xsl:otherwise> <xsl:text>"</xsl:text> <xsl:value-of select="."/> <xsl:text>"</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template>
The upper template applies the lower template to the child nodes of element nodes called 'element', one 'element' at a time. The lower template determines whether the node has any child elements. If it doesn't, it prints the node. Otherwise, it recursively applies this template to the child nodes that were present. Finally, a comma is placed for each element that isn't the last in the node-set. What's a bit tricky here is that no comma is placed for the last grandchild of an 'element', so you might expect those to be missing, but that one is provided by the comma after the element itself.
This could be you. You could be known as a good friend, a well-liked colleague, a devoted husband and a loving father and still this could be you. Remember that, next time you feel like flaming someone for their stupidity or their evilness. They may be just like you, only less lucky.
Inspired by Daniel Dennetts account of the same incident in his book Freedom Evolves
and he's partially right. Some research targets of science, even in physics, are subject to too many independent variables. This results in theories that are very vulnerable to changes: if you change only a small thing, the predictions the theory make will vary wildly. Theories explaining the formation of solar systems are such research targets and it may well be said that "we don't have a fucking clue".Whatever... this is naval gazing and conjecture, no more credible than Intelligent Design. These guys have a few data points, they create a highly convoluted system that seems to account for their data points, then the moment they get more data, they start over. Again and again.
A good critical thinker should know when to say "We don't have a fucking clue" if they want to be taken seriously. But then, it's all about money, isn't it?
However, I don't agree with his implicit conclusion that such research targets should not receive any funding. We are still interested in knowing the answers these researchers are looking for. Even a bad theory is better than no theory: they need some starting point.
Of course, alternate theories should be encouraged. If someone wishes to explain the formation of solar systems by starting from Genesis: go ahead. However, it turns out that the current scientific theories, despite lacking predictive power, are considered to be more satisfactory to most than competing theories. Theories that are based on Genesis that explain the formation of solar systems, need for more adaptations to change their predictions from "solar systems are like ours" to "solar systems are unlike ours". So we fund th scientific ones, as they seem the most promising.
Ending with a funny /. comment:
Though I don't think this is only funny: perhaps the connotations of 'Uranus' so often result in the culturally imprinted response of embarassment, that you cannot get a research program to start.I'm no expert, but as I recall the major problem with probes into the gas giants is that the immense pressure inside of them would crush anything we're capable of making, and electromagnetic interference from the constant storms would make it impossible to transmit any data out.
Plus, every time anyone mentions sending probes into Uranus over at NASA, nobody can stop giggling long enough to seriously work on the problem.
And for the conclusion: http://scienceblogs.com/p...reat_desecration.php#more