[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XML/XSLT Problem
At 2002-07-29 15:30 -0400, Alex Genis wrote:
I have input XML Document like this: ... I need to create XSLT Stylesheet which retrieves from this XML only those elements "PP", "IP" and "PR" where: (PP/IPI/@id = IP/@id) and (IP/@id-1 = PR/@id). ... If beeing already within <xsl:template match="abc"> I use <xsl:apply-templates select="PP|IP|PR"> - I can not refer to the attributes of this elements ("id" and "id-1") because this attribute names are not unique. I'm not sure what you are saying in the last sentence I quoted above. Can somebody give me a hint how can I solve this problem? Attached below is a stylesheet that matches the limited data example you have, and I think it expresses what you want from your English description. The IP element is what is common between the IPI element and the PR element, so I used that as the focus of the stylesheet. My use of variables is to improve speed by reducing the accesses to the source node tree. The key to the solution is the node-set comparison in XSLT will check each node in a node-set in a single test. I hope this helps. ................. Ken
<xsl:output indent="yes"/> <xsl:template match="/ABC"> <xsl:apply-templates select="abc"/> </xsl:template> <xsl:template match="abc"> <abc> <xsl:variable name="IPI-ids" select="PP/IPI/@id"/> <xsl:variable name="PR-ids" select="PR/@id"/> <xsl:variable name="common-IPs" select="IP[@id=$IPI-ids and @id-1=$PR-ids]"/> <xsl:copy-of select="PP[IPI/@id=$common-IPs/@id]"/> <xsl:copy-of select="$common-IPs"/> <xsl:copy-of select="PR[@id=$common-IPs/@id-1]"/> </abc> </xsl:template> </xsl:stylesheet> T:\ftemp>xt alex.xml alex.xsl alex.out T:\ftemp>type alex.out <?xml version="1.0" encoding="utf-8"?> <abc> <PP id="111" id-1="222"> <IPI id="333" id-2="444"> <p1>p1p1p1</p1> </IPI> <IPI id="sss" id-2="666"> <p1>p2p2p2</p1> </IPI> </PP> <IP id="sss" id-1="bbb"> <i1>i2i2i2</i1> </IP> <PR id="bbb"> <r1>r2r2r2</r1> </PR> </abc> T:\ftemp>rem Done!
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-07-1 Practical Formatting Using XSLFO XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed), articles, training (instructor-live,Internet-live,web/CD,licensed) Next public training: 2002-08-05,26,27,09-30,10-03,07,10 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
|