Subject: RE: How to manipulate XML based on attribute? From: Mary Cha <MCha@xxxxxxxxxx> Date: Wed, 19 Jul 2000 14:20:25 -0400 |
Sean: Here is something rough. Try using something like: <xsl:template> <BODY> <xs;:apply-templates select="*"/> </BODY> </xsl:template> <xsl:template match="person/name"> <xsl:choose> <xsl:when test="@vip"> <em><h1><xsl:value-of/></h1></em> </xsl:when> <xsl:otherwise> <xsl:value-of/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="person/friend"> <xsl:choose> <xsl:when test="@vip"> <em><xsl:value-of/></em> </xsl:when> <xsl:otherwise> <xsl:value-of/> </xsl:otherwise> </xsl:choose> </xsl:template> if the @vip attribute is not present in the XML then it will go through the xsl:otherwise. Mary -----Original Message----- From: Timm, Sean To: XSL List (E-mail) Sent: 7/19/00 12:17 PM Subject: Q: How to manipulate XML based on attribute? I've got the following XML file: ============= <Page> <Person> <Name vip="true">John Smith</Name> <Friend>Joe Blow</Friend> </Person> </Page> ============= The vip attribute could occur on any element (this is a simplified structure just for example purposes, so assume there could be many different elements besides just these). In other words, it could occur on the Person element, or the Friend element, or not at all. Wherever the vip attribute appears, I want to embed the result of whatever I do with that element in <em></em> tags in the resultant HTML. For the example given above, I'd want the resultant HTML to look like the following: <html> <body> <em><h1>John Smith</h1></em> Joe Blow </body> </html> So, obviously in the standard XSL, I'm embedding the Name element in a <h1> tag. However, since it specifies the vip attribute, I need to embed the resultant manipulation of that tag in an <em> element. Since I don't know which element the attribute may appear on, I need a generic way to handle it. Is this possible? What would the XSL need to look like to do this kind of manipulation (especially where I don't know on which element the attribute could occur)? Thanks for your help! - Sean T. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: xsl:choose and xsl:when, David Carlisle | Thread | RE: How to manipulate XML based on , Kay Michael |
Re: Conditinally including an XSL, Mike Brown | Date | Re: XSL as a Programming Language, Scott_Boag |
Month |