Subject: Re: [xsl] pulling child elements up to sibling level From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 23 May 2003 17:51:29 +0100 |
My target schema only allows lists and such as siblings of paragraphs, thus I need to transform the document into something like this: This is what I use in the stylesheet for the mathml spec to pull inline lists tables and stuff out for the utterly useless content model of an html p. Adjust the list of elements to taste. <!-- NESTED PARAGRAPHAS --> <!-- xmlspec, like most document formats other than html, allows block level elements in paragraphs. For hTML need to separately wrap each conecutive run of inline elements in <p> and leave block level elements outside the p. xmlspec.xsl has some code using disable-output-escaping to attempt to do this, but it doesn't really work, even with processors that support d-o-e. The original mathml stylesheet as used for mathml 1.01 had code to deal with this, but this is a more efficient implementation using the grouping technique using keys. --> <xsl:key name="pnodes" match="p/node()" use="generate-id((..| (preceding-sibling::*|.)[ self::eg or self::glist or self::olist or self::ulist or self::slist or self::orglist or self::table or self::issue or self::note or self::processing-instruction() or self::graphic[not(@role='inline')] ])[last()])"/> <xsl:template match="p"> <xsl:variable name="p1"> <p> <xsl:if test="@id"> <xsl:attribute name="id"><xsl:value-of select="translate(@id,'_','.')"/></xsl:attribute> </xsl:if> <xsl:if test="@role"> <xsl:attribute name="class"> <xsl:value-of select="@role"/> </xsl:attribute> </xsl:if> <xsl:apply-templates select="key('pnodes',generate-id(.))"/> </p> </xsl:variable> <xsl:if test="key('pnodes',generate-id(.))/self::* or normalize-space($p1)"> <xsl:copy-of select="$p1"/> </xsl:if> <xsl:for-each select="eg|glist|olist|ulist|slist|orglist| table|issue|note|processing-instruction()| graphic[not(@role='inline')]"> <xsl:apply-templates select="."/> <xsl:variable name="p" select="key('pnodes',generate-id(.))[position() > 1]"/> <xsl:if test="$p[self::* or normalize-space(.)]"> <p> <xsl:apply-templates select="$p"/> </p> </xsl:if> </xsl:for-each> </xsl:template> <!-- END OF NESTED PARAGRAPHAS --> ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] pulling child elements up to , Rick Geimer | Thread | Re: [xsl] pulling child elements up, Rick Geimer |
[xsl] two questions, Nathan Shaw | Date | RE: [xsl] Axis order and variables, Michael Kay |
Month |