Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL: need to match by attribute 1

Status
Not open for further replies.

Miros

Programmer
Jan 27, 2001
506
US
XML snippet:
Code:
  <packages ptype="Skintone" isOrphan="false" isBroken="false" ptype2="2">

I need to find all the "package" elements with attribute ptype=Skintone and ignore the others.

My current attempt is:
Code:
	<xsl:template match="package[@ptype = 'Skintone']">
		<xsl:apply-templates/>
	</xsl:template>
		
	<xsl:template match="package">
		// <xsl:apply-templates/>
	</xsl:template>

Please help!
 
Just realized I used the wrong comment mark in the example. Removed line instead; still doesn't work.
Code:
    <xsl:template match="package" />
 
Code:
<package[COLOR=white red]s[/color] ptype="Skintone"
Code:
<xsl:template match="[COLOR=white red]package[/color]" />

The template won't match the XML excerpt due to element name mismatch.

Tom Morrison
 
Duh! Ok, I fixed that, and added a line to verify that the match really was happening:
Code:
	<xsl:template match="packages[@ptype = 'Skintone']">
		<b>Skintone:</b>
		<xsl:apply-templates/>
	</xsl:template>

However, the other "packages" elements are still being processed. Adding the line:
Code:
	<xsl:template match="packages"/>[/quote]
causes all packages, including the "Skintone" ones, to be skipped.  How do I specify "all packages which do not have ptype=Skintone"?
 
Figured it out!

Code:
	<xsl:template match="packages">
		<xsl:if test="@ptype = 'Skintone'"> 
			<b>Skintone:</b>
			<xsl:apply-templates select="filename|subfolder"/>
			<br />
		</xsl:if>
	</xsl:template>

The <xsl:if statement prevents the processing of non-Skintone package elements and the select attribute gets just the two sub-elements I want!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top