S
Simon Brooke
I've been aware for a long time that I have been missing tricks on
control of whitespace in XSL output. I strongly dislike situations
where whitespace is significant, but I'm increasingly hitting them. In
a problem I'm working on at present I have an XSL document (amed-
dbdef.xsl) which transforms one XML document (amendments.xml) into an
XSL document (amend-dbdef.xsl) which then transforms an automatically
generated database schema into a hibernate mapping:
<target name="amend-dbd" depends="parsedbd"
description="update the automatically generated database
definition with amendments">
<style style="${transforms}/amend-dbdef.xslt" destdir="${tmpdir}"
extension=".auto.xslt" in="BusinessModel/amendments.xml"/>
<style style="${tmpdir}/amendments.auto.xslt" destdir="${tmpdir}"
extension=".amended.xml" in="${mapping-generator}/database-
definition.xml"/>
</target>
<target name="nhibernate" depends="amend-dbd"
description="compiles hibernate mapping from the compiled
database description">
<style style="${mapping-generator}/dbdef2hibernate-mapping.xsl"
destdir="${tmpdir}"
extension=".hbm.auto.xml">
<infiles basedir="${tmpdir}">
<include name="database-definition.amended.xml"/>
</infiles>
</style>
<copy file="${tmpdir}/database-definition.amended.hbm.auto.xml"
tofile="${entities}/hibernate-mapping.auto.hbm.xml"/>
</target>
The problem with this is that NHibernate chokes on whitespace inside
certain elements. In consequence I'm currently using 'indent="no"' in
my xsl-output directive on the dbdef2hibernate-mapping.xsl transform,
even though it makes the output code much harder to read. I'd much
rather be able to direct the XSL processor to tag-minimise empty tags
on output, but I don't know how to do this.
Another problem that I've been aware of for some time but which has
become a more critical issue in this process is white space inside
attribute values. For example,
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xslo="http://www.w3.org/1999/XSL/TransformAlias">
[...]
<xsl:template match="entity[@ignore='true']">
<xslo:template>
<xsl:attribute name="match">entity[@name='<xsl:value-of
select="@name"/>']</xsl:attribute>
<xslo:comment>
Ignore table '<xsl:value-of select="@name"/>'
</xslo:comment>
</xslo:template>
</xsl:template>
generates code which is semantically different from
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xslo="http://www.w3.org/1999/XSL/TransformAlias">
[...]
<xsl:template match="entity[@ignore='true']">
<xslo:template>
<xsl:attribute name="match">
entity[@name='<xsl:value-of select="@name"/>']
</xsl:attribute>
<xslo:comment>
Ignore table '<xsl:value-of select="@name"/>'
</xslo:comment>
</xslo:template>
</xsl:template>
I'd like to be able to tell the XSL processor to normalise space in
all attribute values - that is, trim out leading and trailing white
space - but again I don't know how to.
Can anyone give me pointers? Is there a good tutorial on control of
whitespace on the Web? I have searched, but I haven't found one.
Cheers
Simon
control of whitespace in XSL output. I strongly dislike situations
where whitespace is significant, but I'm increasingly hitting them. In
a problem I'm working on at present I have an XSL document (amed-
dbdef.xsl) which transforms one XML document (amendments.xml) into an
XSL document (amend-dbdef.xsl) which then transforms an automatically
generated database schema into a hibernate mapping:
<target name="amend-dbd" depends="parsedbd"
description="update the automatically generated database
definition with amendments">
<style style="${transforms}/amend-dbdef.xslt" destdir="${tmpdir}"
extension=".auto.xslt" in="BusinessModel/amendments.xml"/>
<style style="${tmpdir}/amendments.auto.xslt" destdir="${tmpdir}"
extension=".amended.xml" in="${mapping-generator}/database-
definition.xml"/>
</target>
<target name="nhibernate" depends="amend-dbd"
description="compiles hibernate mapping from the compiled
database description">
<style style="${mapping-generator}/dbdef2hibernate-mapping.xsl"
destdir="${tmpdir}"
extension=".hbm.auto.xml">
<infiles basedir="${tmpdir}">
<include name="database-definition.amended.xml"/>
</infiles>
</style>
<copy file="${tmpdir}/database-definition.amended.hbm.auto.xml"
tofile="${entities}/hibernate-mapping.auto.hbm.xml"/>
</target>
The problem with this is that NHibernate chokes on whitespace inside
certain elements. In consequence I'm currently using 'indent="no"' in
my xsl-output directive on the dbdef2hibernate-mapping.xsl transform,
even though it makes the output code much harder to read. I'd much
rather be able to direct the XSL processor to tag-minimise empty tags
on output, but I don't know how to do this.
Another problem that I've been aware of for some time but which has
become a more critical issue in this process is white space inside
attribute values. For example,
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xslo="http://www.w3.org/1999/XSL/TransformAlias">
[...]
<xsl:template match="entity[@ignore='true']">
<xslo:template>
<xsl:attribute name="match">entity[@name='<xsl:value-of
select="@name"/>']</xsl:attribute>
<xslo:comment>
Ignore table '<xsl:value-of select="@name"/>'
</xslo:comment>
</xslo:template>
</xsl:template>
generates code which is semantically different from
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xslo="http://www.w3.org/1999/XSL/TransformAlias">
[...]
<xsl:template match="entity[@ignore='true']">
<xslo:template>
<xsl:attribute name="match">
entity[@name='<xsl:value-of select="@name"/>']
</xsl:attribute>
<xslo:comment>
Ignore table '<xsl:value-of select="@name"/>'
</xslo:comment>
</xslo:template>
</xsl:template>
I'd like to be able to tell the XSL processor to normalise space in
all attribute values - that is, trim out leading and trailing white
space - but again I don't know how to.
Can anyone give me pointers? Is there a good tutorial on control of
whitespace on the Web? I have searched, but I haven't found one.
Cheers
Simon