patternMinor
Making a flat file
Viewed 0 times
flatmakingfile
Problem
Source XML (since I haven't bothered with a schema):
and here is the actual XSLT I would like a review of.
It is supposed to turn the XML in to a human readable flat file (and does except for addresses which I am still working on):
Nicholas Example
Nick
oxinabox
04 1234 1234
Contrived Apartments
5 Some Rd
Newtown ST
examplen@work.com
nick99@ManMail.com
http://www.a2b3c4.com
and here is the actual XSLT I would like a review of.
It is supposed to turn the XML in to a human readable flat file (and does except for addresses which I am still working on):
AKA
Ph ( ):
Email ( ):
Website:
,
-->
Bank Details:
------------
Account:
-
Solution
Consider using XSLT 2.0, which can't hurt but could help if you need a XSLT 2.0 function in the future. Also note that you don't need
omit-output-declaration since you're outputing text. Ditto for indent.
This is the default template for every element, which means it's not needed.
Why the
//? It makes more sense without it, eg. match="Email". This applies to all your templates.
Ph ( ):
You're using
xsl:text too much. This could become:Ph (): Besides, I'm not sure
context is a good choice for an attribute name. "Context node" already has a specific meaning in XSLT.Code Snippets
<xsl:output
method="text"
omit-xml-declaration="yes"
indent="no"
media-type="text/plain"/><xsl:template match="ContactDetails">
<xsl:apply-templates/>
</xsl:template><xsl:template match="//Email"><xsl:text>
Ph (</xsl:text><xsl:value-of select="@context"/> <xsl:text>): </xsl:text>
<xsl:value-of select = "."/>Ph (<xsl:value-of select="@context"/>): <xsl:value-of select = "."/>Context
StackExchange Code Review Q#10125, answer score: 3
Revisions (0)
No revisions yet.