[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:key
Rhonda, >I would like to extract all paragraphs that have an attribute >of doc equal to contract. Instead I only receive the following >output and I was hoping to understand why? OK. First let's have a look at your input: <Template> <Destination> <Target doc="contract"/> <Para>CONTRACT para destined for output to contract.xml</Para> </Destination> </Template> .... other para's all with different doc value according to DTD Note here that the 'Target' element is an empty one: it does not contain the paragraph that it refers to. This contradicts your DTD, which says that the 'Target' element should *contain* a 'Content' element rather than be *followed by* a 'Para' element. I'll assume that your sample XML is what you want, rather than the DTD. Now have a look at your key: <xsl:key name="blueprint" match="Target" use="@doc"/> Here you are making a key in which the 'Target' elements are indexed according to their 'doc' attribute. When you use it later: <xsl:template match="Destination"> <xsl:element name="{name()}"> <xsl:copy-of select="key('blueprint', '$contractType')"/> </xsl:element> </xsl:template> you want to get the *Para* elements that follow that particular 'Target' element, but instead are getting the 'Target' elements themselves (or would be if you didn't quote the $contractType variable). So, I'd change the way you define and use the key. Keys should generally match the elements that you're actually interested in, which in this case is the 'Para' elements. You can use anything reachable by an XPath expression from that element as a key, so: <xsl:key name="blueprint" match="Para" use="../Target/@doc" /> and <xsl:template match="Destination"> <xsl:element name="{name()}"> <xsl:copy-of select="key('blueprint', $contractType)"/> </xsl:element> </xsl:template> Note that this will only get one paragraph - if there are multiple paragraphs with the same value for the 'doc' attribute, then you should iterate over them using xsl:for-each. This has been tested on your sample input and works with SAXON. I hope that this helps, Jeni Dr Jeni Tennison Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE Telephone 0115 9061301 ? Fax 0115 9061304 ? Email jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|