xslt - I get expected output only if I remove the strip-spaces -
i'm writing xslt in below xml
<?xml version="1.0" encoding="utf-8"?> <body> <para> <page num="794"/>20 july 2009 </para> <para> cont1<case> <casename> <content-style font-style="italic">cont1</content-style> & <content-style font-style="italic">drs</content-style> </casename> <content-style font-style="italic">cont1</content-style> </case> cont1 <case> <casename> <content-style font-style="italic">cont1</content-style> & <content-style font-style="italic">cont1</content-style> & <content-style font-style="italic">mergcont</content-style> </casename> <content-style font-style="italic">[2004] 3 108</content-style> </case> regarding postponement. </para> <casename> <content-style font-style="italic">link1</content-style> & <content-style font-style="italic">drs</content-style> </casename> </body>
and below xslt
<?xml version="1.0" encoding="utf-8" ?> <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:htm="http://www.w3.org/tr/html5/" exclude-result-prefixes="#all"> <xsl:output method="html" doctype-public="xslt-compat" omit-xml-declaration="yes" encoding="utf-8" indent="yes" /> <xsl:template match="/"> <hmtl> <head> <title>new version!</title> </head> <xsl:apply-templates/> </hmtl> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template name="para" match="para"> <xsl:apply-templates select="./node()[1][self::page]" mode="first"/> <xsl:apply-templates select="./phrase/following-sibling::node()[1][self::page]" mode="first"/> <div> <xsl:choose> <xsl:when test="./@align"> <xsl:attribute name="class"><xsl:text>para align-</xsl:text><xsl:value-of select="./@align"/></xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:attribute name="class"><xsl:text>para</xsl:text></xsl:attribute> </xsl:otherwise> </xsl:choose> <xsl:if test="./@num"> <xsl:variable name="phrl"> <xsl:value-of select="string-length(./@num)"/> </xsl:variable> <xsl:variable name="phrase"> <xsl:value-of select="concat('p',./@num)"/> </xsl:variable> <xsl:variable name="newphrase" select="translate($phrase,'.','-')"/> <a> <xsl:attribute name="name"><xsl:value-of select="$newphrase"> </xsl:value-of></xsl:attribute> <span class="phrase"> <xsl:value-of select="./@num"/> </span> </a> </xsl:if> <xsl:choose> <xsl:when test="./phrase/following-sibling::node()[1][self::page]"> <xsl:apply-templates select="child::node() except descendant::page[1]"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> <!--<xsl:apply-templates/>--> </div> </xsl:template> <xsl:template match="casename"> <xsl:apply-templates/> </xsl:template> <xsl:template match="page[not(preceding-sibling::node()[not(self::text()) or normalize-space()])]"/> <xsl:template match="page" mode="first"> <xsl:variable name="pgn"> <xsl:value-of select="./@num"/> </xsl:variable> <xsl:processing-instruction name="pb"> <xsl:text>label='</xsl:text> <xsl:value-of select="$pgn"/> <xsl:text>'</xsl:text> <xsl:text>?</xsl:text> </xsl:processing-instruction> <a name="{concat('pg_',$pgn)}"/> </xsl:template> <xsl:template match="page"> <xsl:variable name="pgn"> <xsl:value-of select="./@num"/> </xsl:variable> <xsl:processing-instruction name="pb"> <xsl:text>label='</xsl:text> <xsl:value-of select="$pgn"/> <xsl:text>'</xsl:text> <xsl:text>?</xsl:text> </xsl:processing-instruction> <a name="{concat('pg_',$pgn)}"/> </xsl:template> </xsl:transform>
in xslt, when remove <xsl:strip-space elements="*"/>
, i'm getting exact output. i'm not getting page
template matched, when add <xsl:strip-space elements="*"/>
, page
template matched, there spaces missing in html. below screenshots.
with <xsl:strip-space elements="*"/>
here page
matched, can see there spaces missing before , after &
without <xsl:strip-space elements="*"/>
here page
not matched
here working demo. http://xsltransform.net/ppzifqu/1
please let me know, how can spaces , page
template matching.
thanks
remove line <xsl:template match="page[not(preceding-sibling::node()[not(self::text()) or normalize-space()])]"/>
. matching when spaces not stripped, , such following template not matched.
Comments
Post a Comment