xsl-list
[Top] [All Lists]

RE: Re: Restrict Mixed Content

2005-01-11 10:03:04
At 11:33 AM 1/11/2005, 'twas written:
> The source is coming from MS Word documents.  I only want to be
> able to use
> data such as bullets, lists, and tables.  All other elements I
> would like to
> ignore like graphs, images, etc.

Something like this...

        <!-- ignore everything -->
        <xsl:template match="*" />

        <!-- ...except for elements X, Y and Z -->
        <xsl:template match="X|Y|Z">
          <xsl:copy>
                <xsl:apply-templates mode="copy" select="*|*@" />
        <xsl:copy>
        </xsl:template>

        <xsl:template match="*|*@|text()" mode="copy" />
           <xsl:copy/>
        <xsl:template>

Watch out ... on this example:

<Q>
  <X>
    ... stuff ...
  </X>
  <Y>
    ... stuff ...
  </Y>
  <Z>
    ... stuff ...
  </Z>
</Q>

the above stylesheet would result in an empty document (nothing would be copied).

You could debug it by switching

<!-- ignore everything -->
<xsl:template match="*" />

to

<!-- by default, pass everything without copying
     (though since this template is built in it doesn't
      have to be included literally) -->
<xsl:template match="*">
  <xsl:apply-templates/>
</xsl:template>

<!-- by default, suppress text nodes
     (wanted text nodes are picked up in 'copy' mode -->
<xsl:template match="text()"/>

and also tweak

<xsl:template match="X|Y|Z">
  <xsl:copy>
    <xsl:apply-templates mode="copy" select="*|*@" />
  <xsl:copy>
</xsl:template>

to say <xsl:apply-templates mode="copy" select="node()|@*"/> -- since by selecting "*|@*" you'll skip the text nodes. (Or just say plain xsl:apply-templates mode="copy" and add an <xsl:copy-of select="@*"/> ahead of it to grab the attributes.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>