XSLT is a language designed to translate XML documents into other XML documents.
I've been using it for the past year or so and I have to say, that the syntax is less than optimal and a lot of expressions are unintuitive. BUT, it IS really simple and fast. I find myself using it whenever I need to transform any XML. I can discard 90% of a document with just a little XSL. Something like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Person">
<Person>
<Name><xsl:value-of select="FullName"/></Name>
<Address><xsl:value-of select="Address"/></Address>
<Phone><xsl:value-of select="Phone[1]"/></Phone>
</Person>
</xsl:template>
</xsl:stylesheet>
One thing I always forget is the "identity" template. It's complicated and non standard. It'd be nice if there was an easier way to copy an entire document other than this...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I had to google this in order to figure it out. There should really be a simple way to copy node OTHER than the <xsl:copy element. And if you want to change something about the identity template, like changing a node's namespace or anything with logic, good luck. Dealing with logic in XSL is hard. If statements turn ugly and large real quick and you might have use "variables" where you didn't think you needed to. Which brings me to another pain point of XSL. "variables" aren't variables at ALL. They're just static placeholders with 1 single value. Once they're set, they CANNOT be changed. This is really unintuitive for programmers. I've heard the argument that they resemble variable in math, but I don't buy that either. Math variables are more static than in Computer Science, but they DO VARY. "variables" in XSL DON'T vary at all.
Also, as a programmer, I try to split up problems into smaller problems. So in XSL, if I have some complex logic to perform, I'll split it up into methods. But functions in XSL aren't easy either. They DO exist, but they're not called functions or methods, they're just named templates that you HAVE to pass arguments to. And the syntax for THAT is awful. Each parameter takes a full line to declare.
So, long story short, I think XSL could be a lot better. It's a great idea and it is VERY useful for transforming XSL. But just because it's the best tool out there for the task, doesn't mean there isn't A LOT of room for improvment. I think there could be a much more elegant language out there for describing transformation tasks. Maybe even one that ISN'T based on XML! *gasp* Maybe something completly new!
Tuesday, October 16, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment