S
Simon Brooke
I'm trying to write an XSL template to generate Google's data input
format for blogger, which is documented here: http://goo.gl/tydYA
As you can see, it has the particularly delightful property that the
content of the 'content' element actually /is/ markup, but has been
inlined or entified so that it appears as raw text. Yes, I know this is
bizarre and ugly, but I don't control it - Google do. And as there's no
documentation on how to import normally-well-formed XML, this is what I
need to generate.
I've been trying to write a template which does this awful mangling,
and what I've come up with seems to work:
<xsl:template name="mangle-xml">
<xslaram name="content"/>
<xsl:choose>
<xsl:when test="$content/*">
<<xsl:value-of select="local-name()"/>
<xsl:for-each select="$content/@*">
<xsl:value-of select="concat(' ', local-name(),
'="', ., '"')"/>
</xsl:for-each>>
<xsl:for-each select="$content/node()">
<xsl:call-template name="mangle-xml">
<xsl:with-param name="content" select="."/>
</xsl:call-template>
</xsl:for-each>
</<xsl:value-of select="local-name()"/>>
</xsl:when>
<xsltherwise>?text?
<xsl:value-of select="$content"/>
</xsltherwise>
</xsl:choose>
</xsl:template>
This mangles the XML correctly(!), but it's pretty ugly, dark and
mysterious. Is there a cleaner way of doing this?
--
http://www.journeyman.cc/~simon/ :: PGP public key on home page
;; USER ERROR: replace user and press any key to continue
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAk00WPoACgkQPj28Ek2lI8X4rwCgsA+l1yGGMV2pXho124NuDzBP
0yMAn23M0QVt2FDVn2EMGcSY179rwyqW
=0j07
-----END PGP SIGNATURE-----
format for blogger, which is documented here: http://goo.gl/tydYA
As you can see, it has the particularly delightful property that the
content of the 'content' element actually /is/ markup, but has been
inlined or entified so that it appears as raw text. Yes, I know this is
bizarre and ugly, but I don't control it - Google do. And as there's no
documentation on how to import normally-well-formed XML, this is what I
need to generate.
I've been trying to write a template which does this awful mangling,
and what I've come up with seems to work:
<xsl:template name="mangle-xml">
<xslaram name="content"/>
<xsl:choose>
<xsl:when test="$content/*">
<<xsl:value-of select="local-name()"/>
<xsl:for-each select="$content/@*">
<xsl:value-of select="concat(' ', local-name(),
'="', ., '"')"/>
</xsl:for-each>>
<xsl:for-each select="$content/node()">
<xsl:call-template name="mangle-xml">
<xsl:with-param name="content" select="."/>
</xsl:call-template>
</xsl:for-each>
</<xsl:value-of select="local-name()"/>>
</xsl:when>
<xsltherwise>?text?
<xsl:value-of select="$content"/>
</xsltherwise>
</xsl:choose>
</xsl:template>
This mangles the XML correctly(!), but it's pretty ugly, dark and
mysterious. Is there a cleaner way of doing this?
--
http://www.journeyman.cc/~simon/ :: PGP public key on home page
;; USER ERROR: replace user and press any key to continue
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAk00WPoACgkQPj28Ek2lI8X4rwCgsA+l1yGGMV2pXho124NuDzBP
0yMAn23M0QVt2FDVn2EMGcSY179rwyqW
=0j07
-----END PGP SIGNATURE-----