RE: [Q] Possible to select all attributes except some?

"Kay, Michael" <[email protected]> Sat, 22 Nov 2003 23:22:04 +0100
Newsgroups gmane.text.xml.xpath.general
Message-ID <[email protected]>
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C3B147.0ECA9E20
Content-Type: text/plain

This is easy in XPath 2.0:

  select="@* except @background"

In XPath 1.0, you have to write something like

  select="@*[local-name() != 'background']"

Michael Kay



> -----Original Message-----
> From: Steinar Bang [mailto:[email protected]] 
> Sent: 22 November 2003 14:55
> To: [email protected]
> Subject: [Q] Possible to select all attributes except some?
> 
> 
> 
> Is it possible to write an XPath expression to select all 
> attributes, except some.
> 
> The context is that the new Web interface of the Gmane 
> mail<->NNTP gateway[1] will use an XSLT style sheet to 
> transform HTML emails to harmless HTML, by stripping 
> everything in HTML that may be exploited[2]. 
> 
> The style sheet use the following construct to copy elements 
> that should be preserved:
> 
> <xsl:template match="h1|h2|h3|h4|h5|h6|p|a|td">
>   <xsl:element name="{name(.)}">
>     <xsl:copy-of select="@*"/>
>     <xsl:apply-templates/>
>   </xsl:element>
> </xsl:template>
> 
> Is it possible to replace "@*" with an expression that would 
> select all attributes except the attribute named "background"[3][4]?
> 
> Thanx!
> 
> 
> - Steinar
> 
> [1] <http://gmane.org/>
> [2] <http://article.gmane.org/gmane.discuss/4353>
> [3] <http://article.gmane.org/gmane.discuss/4525>
> [4] <http://article.gmane.org/gmane.discuss/4526>
> 

------_=_NextPart_001_01C3B147.0ECA9E20
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>RE: [Q] Possible to select all attributes except some?</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>This is easy in XPath 2.0:</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; select=3D&quot;@* except =
@background&quot;</FONT>
</P>

<P><FONT SIZE=3D2>In XPath 1.0, you have to write something like</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp; select=3D&quot;@*[local-name() !=3D =
'background']&quot;</FONT>
</P>

<P><FONT SIZE=3D2>Michael Kay</FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=3D2>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=3D2>&gt; From: Steinar Bang [<A =
HREF=3D"mailto:[email protected]">mailto:[email protected]</A>] </FONT>
<BR><FONT SIZE=3D2>&gt; Sent: 22 November 2003 14:55</FONT>
<BR><FONT SIZE=3D2>&gt; To: [email protected]</FONT>
<BR><FONT SIZE=3D2>&gt; Subject: [Q] Possible to select all attributes =
except some?</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Is it possible to write an XPath expression to =
select all </FONT>
<BR><FONT SIZE=3D2>&gt; attributes, except some.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; The context is that the new Web interface of =
the Gmane </FONT>
<BR><FONT SIZE=3D2>&gt; mail&lt;-&gt;NNTP gateway[1] will use an XSLT =
style sheet to </FONT>
<BR><FONT SIZE=3D2>&gt; transform HTML emails to harmless HTML, by =
stripping </FONT>
<BR><FONT SIZE=3D2>&gt; everything in HTML that may be exploited[2]. =
</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; The style sheet use the following construct to =
copy elements </FONT>
<BR><FONT SIZE=3D2>&gt; that should be preserved:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; &lt;xsl:template =
match=3D&quot;h1|h2|h3|h4|h5|h6|p|a|td&quot;&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; &lt;xsl:element =
name=3D&quot;{name(.)}&quot;&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:copy-of =
select=3D&quot;@*&quot;/&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;xsl:apply-templates/&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; &lt;/xsl:element&gt;</FONT>
<BR><FONT SIZE=3D2>&gt; &lt;/xsl:template&gt;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Is it possible to replace &quot;@*&quot; with =
an expression that would </FONT>
<BR><FONT SIZE=3D2>&gt; select all attributes except the attribute =
named &quot;background&quot;[3][4]?</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Thanx!</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; - Steinar</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; [1] &lt;<A HREF=3D"http://gmane.org/" =
TARGET=3D"_blank">http://gmane.org/</A>&gt;</FONT>
<BR><FONT SIZE=3D2>&gt; [2] &lt;<A =
HREF=3D"http://article.gmane.org/gmane.discuss/4353" =
TARGET=3D"_blank">http://article.gmane.org/gmane.discuss/4353</A>&gt;</F=
ONT>
<BR><FONT SIZE=3D2>&gt; [3] &lt;<A =
HREF=3D"http://article.gmane.org/gmane.discuss/4525" =
TARGET=3D"_blank">http://article.gmane.org/gmane.discuss/4525</A>&gt;</F=
ONT>
<BR><FONT SIZE=3D2>&gt; [4] &lt;<A =
HREF=3D"http://article.gmane.org/gmane.discuss/4526" =
TARGET=3D"_blank">http://article.gmane.org/gmane.discuss/4526</A>&gt;</F=
ONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C3B147.0ECA9E20--