xsl-list
[Top] [All Lists]

Re: REtrieving attributes with XPATH

2003-09-10 14:34:45
Miguel,

<xsl:template match="article">
  <xsl:copy>
    <xsl:apply-templates select="@articleid|@width|@height"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="@articleid">
  <id>
    <xsl:value-of select="."/>
  </id>
</xsl:template>

<xsl:template match="@width|@height">
  <xsl:element name="{local-name()}">
    <xsl:value-of select="."/>
  </xsl:element>
</xsl:template>

The XPath "@articleid|@width|@height" is short for
"attribute::articleid | attribute::width | attribute::height"

which is simple enough, I think.

Enjoy,
Wendell

At 04:25 PM 9/10/2003, you wrote:
Hi,

imagine that i have this XML,

<article articleid="1" height="5" rating="2" sectionid="1" width="6"
xmlns:src="http://xml.apache.org/xindice/Query"; src:col="/db/daeDocuments"
src:key="1"><title>Corrupção
ambiental</title><text>ilegaisddfdf</text></article>

<article articleid="2" height="4" rating="2" sectionid="1" width="7"
xmlns:src="http://xml.apache.org/xindice/Query"; src:col="/db/daeDocuments"
src:key="1"><title>Corrupção
ambiental</title><text>ilegaisddfdf</text></article>

and i want to retreive something like this

<article>
<id>1</id>
<width>6</width>
<height>5</height>
</article>

<article>
<id>2</id>
<width>7</width>
<height>4</height>
</article>

how can i do it in XSL?


======================================================================
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



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