Subject: [xsl] Merging data based on attributes, revisited From: "Bob Portnell" <simply.bobp@xxxxxxxxx> Date: Thu, 24 Aug 2006 09:27:13 -0700 |
Processing this SVG ... ====================================================================== <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <?xml-stylesheet type="text/xsl" href="newtest.xsl"?>
<svg xmlns="http://www.w3.org/2000/svg" contentStyleType="text/css" contentScriptType="text/ecmascript" version="1.1" zoomAndPan="magnify" preserveAspectRatio="xMidYMid meet" width="100%" height="100%"> <defs/> <desc> Test Page </desc> <!-- TEXT ELEMENTS --> <g font-family="Arial" font-size="24"> <!-- DOCUMENT TITLE --> <text><tspan x="400" y="60" text-anchor="middle">Test Page</tspan></text> </g> <g font-family="Arial" font-size="8" text-anchor="middle" id="k1"> <text x="80" y="140">element phase</text> <!-- Here's the difference --> </g> <g font-family="Arial" font-size="8" text-anchor="middle" id="k2"> <text x="80" y="220">element phase</text> </g> <g font-family="Arial" font-size="8" text-anchor="middle" id="k3"> <text x="80" y="300">element phase</text> </g>
<g fill="none" stroke="black" stroke-width="2"> <rect x="40" y="120" width="80" height="50" pointer-events="all" visibility="visible" /> </g>
<g fill="none" stroke="black" stroke-width="2"> <rect x="40" y="200" width="80" height="50" pointer-events="all" visibility="visible" /> </g>
<g fill="none" stroke="black" stroke-width="2"> <rect x="40" y="280" width="80" height="50" pointer-events="all" visibility="visible"/> </g>
The data I want to pull in is the same... ========================================= <?xml version="1.0" encoding="UTF-8"?>
<test> <data id="k3"> <element>Tritium</element> <phase>plasma</phase> </data> <data id="k2"> <element>Deuterium</element> <phase>solid</phase> </data> <data id="k1"> <element>Hydrogen</element> <phase>gas</phase> </data> </test>
The desired result will put the data items into the SVG with a space between, thus: ===================================================================================== <g font-family="Arial" font-size="8" text-anchor="middle" id="k1"> <text x="80" y="140">Hydrogen gas</text> </g> <g font-family="Arial" font-size="8" text-anchor="middle" id="k2"> <text x="80" y="220">Deuterium solid</text> </g> <g font-family="Arial" font-size="8" text-anchor="middle" id="k3"> <text x="80" y="300">Tritium plasma</text> </g>
Here's the Carlisle-improved stylesheet, botched by me. ======================================================================================= <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" exclude-result-prefixes="svg" >
<!-- copies all nodes/attributes into result tree unchanged --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:template match="svg:text[.=('element phase')]"> <text> <xsl:copy-of select="@*"/> <xsl:value-of select="key(element,../@id,doc('textsrc.xml'))"/> <xsl:text> </xsl:text> <xsl:value-of select="key(phase,../@id,doc('textsrc.xml'))"/> </text> </xsl:template>
<xsl:key name="element" match="element" use="../@id"/> <xsl:key name="phase" match="phase" use="../@id"/>
</xsl:stylesheet> =====================================================================================
This declines to generate any output under Saxon, so I've misunderstood something and thoroughly. Advice and clewbats welcome.
BobP simply.bobp@xxxxxxxxx
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] [XSLT, Version 1] Stylesh, Robert Koberg | Thread | [xsl] Merging data on attributes, r, Bob Portnell |
RE: [xsl] Using attributes with XPa, Michael Kay | Date | [xsl] Email Address Validation, Senthilkumaravelan K |
Month |