[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] how do you determine if a property exists?
Subject: RE: [xsl] how do you determine if a property exists? From: David Buddrige <dbuddrige@xxxxxxxxx> Date: Thu, 15 Apr 2004 18:20:35 -0700 (PDT) |
thanks everyone. The solution I settled on was: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <myoutput> <xsl:apply-templates/> </myoutput> </xsl:template> <xsl:template match="mytag"> <xsl:element name="myelement"> <xsl:attribute name="time"> <xsl:choose> <xsl:when test="@duration=''">1</xsl:when> <xsl:when test="not(@duration)">1</xsl:when> <xsl:otherwise><xsl:value-of select="@duration"/></xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:element> </xsl:template> </xsl:stylesheet> which given the input data: <?xml version="1.0" encoding="iso-8859-1"?> <info> <mytag duration="3 days" /> <mytag /> <mytag duration="6 hours" /> <mytag duration="33 hours" /> <mytag duration="" /> <mytag duration="13 hours" /> <mytag duration="5 days" /> <mytag duration="" /> <mytag duration="3 hours" /> <mytag duration="23 hours" /> </info> produces: <?xml version="1.0" encoding="UTF-8"?><myoutput> <myelement time="3 days"/> <myelement time="1"/> <myelement time="6 hours"/> <myelement time="33 hours"/> <myelement time="1"/> <myelement time="13 hours"/> <myelement time="5 days"/> <myelement time="1"/> <myelement time="3 hours"/> <myelement time="23 hours"/> </myoutput> thanks again! 8-) David. --- Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote: > At 11:49 AM 4/15/2004, 'twas written: > ><xsl:template match="/info"> > ><results> > > <xsl:for-each select='mytag'> > > <xsl:element name='myelement'> > > <xsl:choose> > > <xsl:when test='@duration != ""'> > > <xsl:copy-of select='@duration'/> > > </xsl:when> > > <xsl:otherwise> > > <xsl:attribute > name='duration'>1</xsl:attribute> > > </xsl:otherwise> > > </xsl:choose> > > </xsl:element> > > </xsl:for-each> > ></results> > ></xsl:template> > > Or: > > <xsl:template match="/info"> > <results> > <xsl:for-each select='mytag'> > <myelement duration='1'> > <xsl:copy-of > select='@duration[normalize-space()]'/> > </myelement> > </xsl:for-each> > </results> > </xsl:template> > > Take your pick: clarity vs. succinctness. > > Cheers, > Wendell > > > > ====================================================================== > Wendell Piez > mailto:wapiez@xxxxxxxxxxxxxxxx > 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 > ====================================================================== > __________________________________ Do you Yahoo!? Yahoo! Tax Center - File online by April 15th http://taxes.yahoo.com/filing.html
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] how do you determine if a, Wendell Piez | Thread | RE: [xsl] how do you determine if a, Michael Kay |
Re: [xsl] Context Assignment Questi, Wendell Piez | Date | Re: [xsl] Need guidance producing P, Kazumi Hara |
Month |
Keywords