5 ms·
I just had an exam about XSLT, XML Schema, etc... this morning. My take-away is this. Pick any scripting language (python, ruby, php...) + templating engine and
by AlexanderDhoore 13y ago
I just had an exam about XSLT, XML Schema, etc... this morning. My take-away is this. Pick any scripting language (python, ruby, php...) + templating engine and you'll avoid the World Of Pain that is XSLT.
XSLT is kind of 'declarative', but it has ifs, switches, ... They probably didn't start out with the plan to implement a programming language with xml tags, but they did. It's horrible.
Edit: XML Schema is horrible as well. This is how you define an element with string content, and one attribute (which is VERY basic):
<xs:element name="myElement">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="myAttribute" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Just off the top of my head, I could invent something better, like:
<myElement myAttribute="xs:string">xs:string</myElement>
- snitko 13y agoAhh yes. I tried writing a schema for my document (ocd here, I like things to be valid), but then I realized that the cost/benefit ratio of this process would be completely unreasonable.
- AlexanderDhoore 13y agoIf I had to do it today, I'd probably use DTD to validate the XML tag hierarchy and than use a programming language (with xpath) to validated the attribute and tag contents. XML Schema tries to validate both the tag hierarchy and the contents, which requires data types and complicated definitions. So much overkill... DTD and XPath are actually very nice and simple. This is the DTD equivalent of my XML Schema example above: <!ELEMENT myElement (#PCDATA)> <!ATTLIST myElement myAttribute CDATA> I could see myself writing a small domain language and translate it to DTD, to make it even nicer.
- pjmlp 13y agoThe way I work around XML schema pain is to use visual tools for it, like the ones in Visual Studio, for example. Hand editing XML schema files is too much of a pain.
- mjn 13y agoMy impression is that this is considered the norm in the XML world: you're supposed to edit it via a specialized editor, not directly as raw text.
- T-hawk 13y agoXSLT is purely declarative, not just kind of. Those ifs and switches are not imperative constructs, they're evaluated functionally. xsl:if conditionally applies a template, which kind of looks imperative and control-flowy, but is really functional all the way through. <xsl:if test="x">template</xsl:test> is basically this in Lisp: (if eval(x) (apply-template template) nil) And <xsl:for-each> is equivalent to map in Lisp. It's a functional projection, not an imperative loop, even if the syntax looks like that of an imperative language.
- jzwinck 13y agoRelaxNG would look something like this: <element name="myElement"> <attribute name="myAttribute"> <text/> </attribute> <text/> </element> OK, it's not great, but it's better.