Subject: RE: How dynamic is XSL? From: Søren Neigaard <neigaard@xxxxxxxxxxxxxx> Date: Thu, 10 Aug 2000 19:47:33 +0200 |
Well... I think I'm one step closere now. I have made these two files: --------------------------------------- <?xml version="1.0"?> <?xml-stylesheet href="example.xsl" type="text/xsl" media="explorer"?> <?cocoon-process type="xslt"?> <card> <cardid>index</cardid> <cardtitle>WAP XML Test</cardtitle> <img> <imgalign>center</imgalign> <imgsrc>Graphics/header.wbmp</imgsrc> <imgalt>Header</imgalt> </img> <text> <textalign>left</textalign> <value>Choose a link:</value> </text> <link> <linkalign>left</linkalign> <linkhref>Sub02-A1.jhtml</linkhref> <linktitle>Coastlines</linktitle> </link> <link> <linkalign>left</linkalign> <linkhref>#about</linkhref> <linktitle>About</linktitle> </link> </card> <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <!-- root of XML document --> <xsl:processing-instruction name="cocoon-format">type="text/html"</xsl:processing-instruction> <wml> <template> <do type="prev" label="Back"> <prev/> </do> </template> <xsl:for-each select="card"> <card> <xsl:attribute name="id"> <xsl:value-of select="cardid"/> </xsl:attribute> <xsl:attribute name="title"> <xsl:value-of select="cardtitle"/> </xsl:attribute> <xsl:apply-templates/> </card> </xsl:for-each> </wml> </xsl:template> <xsl:template match="img"> <p> <xsl:attribute name="align"> <xsl:value-of select="imgalign"/> </xsl:attribute> <img> <xsl:attribute name="src"> <xsl:value-of select="imgsrc"/> </xsl:attribute> <xsl:attribute name="alt"> <xsl:value-of select="imgalt"/> </xsl:attribute> </img> </p> </xsl:template> <xsl:template match="link"> <p> <xsl:attribute name="align"> <xsl:value-of select="linkalign"/> </xsl:attribute> <a> <xsl:attribute name="href"> <xsl:value-of select="linkhref"/> </xsl:attribute> <xsl:value-of select="linktitle"/> </a> </p> </xsl:template> <xsl:template match="text"> <p> <xsl:attribute name="align"> <xsl:value-of select="textalign"/> </xsl:attribute> <xsl:value-of select="value"/> </p> </xsl:template> </xsl:stylesheet> --------------------------------------- And I expected this result: --------------------------------------- <wml> <template> <do type="prev" label="Back"> <prev/> </do> </template> <card id="index" title="WAP XML Test"> <p align="center"> <img src="Graphics/header.wbmp" alt="Header"> </p> <p align="left"> Choose a link: </p> <p align="left"> <a href="Sub02-A1.jhtml">Coastlines</a> </p> <p align="left"> <a href="#about">About</a> </p> </card> </wml> --------------------------------------- But I got this instead: --------------------------------------- <wml> <template> <do label="Back" type="prev"> <prev></prev> </do> </template> <card id="index" title="WAP XML Test"> index WAP XML Test <p align="center"> <img alt="Header" src="Graphics/header.wbmp"> </p> <p align="left"> Choose a link: </p> <p align="left"> <a href="Sub02-A1.jhtml">Coastlines</a> </p> <p align="left"> <a href="#about">About</a> </p> </card> </wml> --------------------------------------- What's wrong? -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of Linda van den Brink Sent: 10. august 2000 13:36 To: 'xsl-list@xxxxxxxxxxxxxxxx' Subject: RE: How dynamic is XSL? I assume that you want your output to be an equally arbitrary mix? Then that's easy to accomplish with xsl:template and xsl:apply-templates. Just write a template for each of your elements, and these template rules will fire whenever an element is found in the input document. If you would use xsl:for-each, then as you say if the xsl:for-each selects links, these would be processed first, and then if you have a second xsl:for-each select="text", the text would be processed next. xsl:for-each involves building up the resutl and 'pulling' data from the source file, while xsl:template/apply-templates involves reading the source XML and 'pushing' data to the result. I don't have a sample of your source so I'm leaving it at this rather abstract explanation. Linda 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: How dynamic is XSL?, Søren Neigaard | Thread | RE: How dynamic is XSL?, Jeni Tennison |
Is there an elegant way to copy a D, Joe Ward | Date | RE: Memory-saving Prescription for , Kay Michael |
Month |