Subject: [xsl] empty element sabotages xsl:key revisited From: "Antonie Botes" <antonie.botes@xxxxxxxxxxx> Date: Tue, 11 Feb 2003 17:01:26 -0000 |
>From a post in the archive (http://www.biglist.com/lists/xsl-list/archives/200102/msg00706.html) it seems that a similar problem was encountered, but solved by using a different parser (http://www.biglist.com/lists/xsl-list/archives/200102/msg00728.html). I have tried the following using Xalan 2.4.1, and MSXSL 4.0, with the same results: I use keys to identify a <Structure> by using its first preceding sibling as its lookup value. The effect is that when an element that is followed by a <Structure> in the source, is added to the result tree, the structure is also added (see <xsl:template match="*">). The output is wrong however, and some of the structures are added following some of the empty elements ( e.g. <EnvProfileText/> ). After removing these specific empty elements, the wrong output disappears. I don't have a clue why it behaves as it does, as the 'offending' empty elements has no relation to the key as I see it. Is the problem with the processors, or with my 16:00-in-the-afternoon logic? PS - This is the second part of a 2 phase XSLT conversion. The first part is used to simplify an existing source of XML, the second part is to add structure/grouping to the result. PPS - If I missed an easier/more practical way to do this, please feel free to let me know! Source XML: ----------- <?xml version="1.0" encoding="UTF-16"?> <APMainProfile xmlns:xlink="http://www.w3.org/1999/xlink"> <StructureHeading>STRUCTURE: </StructureHeading> <Structure xlink:href="#./Obj0013D1A7" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <EnvProfileText>Pyriftalid is harmless to earthworms, bees and birds. The product also exhibits low toxicity to fish, daphnia, algae and is not expected to cause risk to aquatic organisms due to its low use rates, fast degradation in the paddy, rapid adsorbtion to sediments, low aqueous solubility and low logP.</EnvProfileText> <!-- Problematic empty element --> <EnvProfileText/> <EnvProfileGeneral>Fate in soil: </EnvProfileGeneral> <SynthesisRouteHeading>SYNTHESIS ROUTES:</SynthesisRouteHeading> <SynthesisRouteDescription> <a xlink:type="simple" xlink:href="../company/syngentaw.htm" ProfileType="company">Syngenta</a> has extensively studied the synthesis routes to pyriftalid and the following conclusions can be made;</SynthesisRouteDescription> <SynthesisRouteHeading/> <Structure xlink:href="#./Obj0013D1A8" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <Structure xlink:href="#./Obj0013D1A9" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /> <Structure xlink:href="#./Obj0013D1AA" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /> </APMainProfile> XSLT Code: ---------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" method="xml"/> <xsl:key name="structures" match="Structure" use="preceding-sibling::*[1]"/> <xsl:template match="/APMainProfile"> <xsl:processing-instruction name="xml-stylesheet">type="text/css" href="APMain.css"</xsl:processing-instruction> <xsl:copy> <StructureSection> <xsl:apply-templates select="StructureHeading | StructureDescription"/> </StructureSection> <EnvProfileSection> <xsl:apply-templates select="EnvProfileHeading | EnvProfileCreature | EnvProfileValue | EnvProfileClass | EnvProfileGeneral | EnvProfileText"/> </EnvProfileSection> <SynthesisRouteSection> <xsl:apply-templates select="SynthesisRouteHeading | SynthesisRouteDescription | SynthesisRouteDiagram"/> <SynthesisRouteDiagram> </SynthesisRouteDiagram> </SynthesisRouteSection> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:copy-of select="."/> <xsl:copy-of select="key('structures', .)"/> </xsl:template> </xsl:stylesheet> Result: ------- <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="APMain.css"?> <APMainProfile xmlns:xlink="http://www.w3.org/1999/xlink"> <StructureSection> <StructureHeading>STRUCTURE: </StructureHeading> <Structure xlink:href="#./Obj0013D1A7" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> </StructureSection> <EnvProfileSection> <EnvProfileText>Pyriftalid is harmless to earthworms, bees and birds. The product also exhibits low toxicity to fish, daphnia, algae and is not expected to cause risk to aquatic organisms due to its low use rates, fast degradation in the paddy, rapid adsorbtion to sediments, low aqueous solubility and low logP.</EnvProfileText> <EnvProfileText/> <!-- Problematic output starts here --> <Structure xlink:href="#./Obj0013D1A8" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <Structure xlink:href="#./Obj0013D1A9" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <Structure xlink:href="#./Obj0013D1AA" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <!-- Problematic output ends here --> <EnvProfileGeneral>Fate in soil: </EnvProfileGeneral> </EnvProfileSection> <SynthesisRouteSection> <SynthesisRouteHeading>SYNTHESIS ROUTES:</SynthesisRouteHeading> <SynthesisRouteDescription> <a xlink:type="simple" xlink:href="../company/syngentaw.htm" ProfileType="company">Syngenta</a> has extensively studied the synthesis routes to pyriftalid and the following conclusions can be made;</SynthesisRouteDescription> <SynthesisRouteHeading/> <Structure xlink:href="#./Obj0013D1A8" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <Structure xlink:href="#./Obj0013D1A9" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <Structure xlink:href="#./Obj0013D1AA" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> <SynthesisRouteDiagram/> </SynthesisRouteSection> </APMainProfile> This email is confidential and is not intended to be read by anyone other than the named recipient. If you have received this email in error, please notify us immediately by reply email and then delete this message from your system: please do not copy this email or use it for any purpose or disclose its contents to any other person (since this could be a breach of confidence) and any hard copy should be destroyed immediately. Thank you for your co-operation. WARNING: please check any attachment for viruses before opening it as PJB Publications Ltd accepts no liability for this email. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Passing parameters from A, bryan | Thread | RE: [xsl] empty element sabotages x, McNally, David |
RE: [xsl] Passing parameters from A, bryan | Date | RE: [xsl] Debugging XSL with XML Sp, Jim Melton |
Month |