[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] a simpler version ???
Hi. I wrote these documents (dtd, xml and xsl) and it runs. But I think that my stylesheet is too complex. For example : <xsl:for-each select="Element[key('Component-Component_context_id',@id)/Component_Core/@Na me]"> <xsl:sort select="key('Component-Component_context_id',@id)/Component_Core/@Name"/> <a href = "#{generate-id(key('Component-Component_context_id',@id))}"> <xsl:value-of select="key('Component-Component_context_id',@id)/Component_Core/@Name" /> Is it possible to write a simpler version which is at least as efficient as mine? To explain briefly, I have a list a components, and I want to produce a table of contents, and a list of each components with for each component the list of all parent component and the list of all children components (and with hyperlinks). Regards, J.C ---The DTD--- <!ELEMENT Components (Components_Elements, Components_Decomposition, Domain_Model)> <!ATTLIST Tamot Version CDATA #REQUIRED > <!ELEMENT Components_Elements (Boolean_Connector | Link | Component)+> <!ELEMENT Boolean_Connector EMPTY> <!ATTLIST Boolean_Connector Name CDATA #REQUIRED id ID #REQUIRED > <!ELEMENT Link (Precondition?)> <!ATTLIST Link id ID #REQUIRED Parent_Component_Name CDATA #REQUIRED id1 IDREF #REQUIRED id2 IDREF #REQUIRED > <!ELEMENT Precondition (#PCDATA)> <!ELEMENT Component (Component_Core,Component_Context+)> <!ELEMENT Component_Core (Semantics,Comment?)> <!ATTLIST Component_Core Name CDATA #REQUIRED > <!ELEMENT Semantics (#PCDATA)> <!ELEMENT Comment (#PCDATA)> <!ELEMENT Component_Context (Precondition?,Feedback?,Postcondition?,Comment?)> <!ATTLIST Component_Context id ID #REQUIRED > <!ELEMENT Feedback (#PCDATA)> <!ELEMENT Postcondition (#PCDATA)> <!ELEMENT Components_Decomposition (Expansion+)> <!ELEMENT Expansion (Element+)> <!ATTLIST Expansion Component_Name CDATA #REQUIRED > <!ELEMENT Element EMPTY> <!ATTLIST Element id IDREF #REQUIRED X CDATA #REQUIRED Y CDATA #REQUIRED > ---------the XSL--------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Stylesheet to generate Table of contents and Details of Components from CardXML output doocument--> <xsl:output method = "html" /> <xsl:param name="top-Component" select="'Root'" /> <!-- indexes the Expansions by Element id --> <xsl:key name="expansion-Element_id" match="Expansion" use="Element/@id" /> <!-- indexes the Expansions by Component_id --> <xsl:key name="expansion-name" match="Expansion" use="@Component_Name" /> <!-- indexes the Components by Component core name --> <xsl:key name="Component-Component_core_name" match="Component" use="Component_Core/@Name" /> <!-- indexes the Components by Component context id --> <xsl:key name="Component-Component_context_id" match="Component" use="Component_Context/@id" /> <!-- On genere de l'HTML --> <xsl:template match="/"> <html> <head> <title>TOC</title> </head> <body> <!-- Menu --> <a href="#TOC">Table of Contents</a> | <a href="#LogicalOrder">Logical Order</a> | <a href="#Detail">Detail</a> <!-- Generation de la table des matieres --> <h1><a name="TOC">Table of Contents</a></h1> <xsl:apply-templates select="Card/Components_Elements" mode="table-of-contents"/> <hr></hr> <!-- Generation du detail des taches --> <h1><a name="Detail">Detail</a></h1> <br></br> <xsl:apply-templates select="Card/Components_Elements" mode="details"/> </body> </html> </xsl:template> <!-- ************ Components mode="table-of-contents" ****************** --> <xsl:template match="Components_Elements" mode="table-of-contents"> <div id="contents"> <xsl:for-each select="Component/Component_Core"> <xsl:sort select="@Name" order="ascending" /> <br><a href = "#{generate-id(key('Component-Component_core_name',@Name))}"><xsl:value-of select="@Name" /></a></br> </xsl:for-each> </div> </xsl:template> <!-- ************ Components mode="details" ***************************** --> <xsl:template match="Components_Elements" mode="details"> <!-- goes through the Components in the order they appear in the input - and sort this alphabetically 1. Find all parents 2. Find all sub-Components ordered by decomposition --> <xsl:for-each select="Component"> <!-- current node = Component --> <xsl:variable name="ComponentName" select="Component_Core/@Name"/> <!-- impossible to use the variable ComponentName here to sort the Component by alphabetical order, so I use the definition of the variable instead the variable --> <xsl:sort select="Component_Core/@Name"/> <p> <!-- define the HTML anchor for the Component --> <a name="{generate-id()}"> <h2> <xsl:value-of select="$ComponentName" /> </h2> </a> </p> <!-- ***** 1. Find all parent Components which use the current Component ****** --> <xsl:for-each select="Component_Context"> <!-- current node = Component Context --> <p> <!-- define a variable to hold the list of Components using the current Component --> <xsl:variable name="parent" select="key('Component-Component_core_name',key('expansion-Element_id', @id)/@Component_Name)" /> Parent = <xsl:choose> <!-- if there are any parents... --> <xsl:when test="$parent"> <!-- go through the parents one by one (document order) --> <xsl:for-each select="$parent"> <xsl:sort select="Component_Core/@Name"/> <a href = "#{generate-id(.)}"> <xsl:value-of select="Component_Core/@Name" /></a> <xsl:if test="position() != last()">, </xsl:if> </xsl:for-each> </xsl:when> <!-- if there aren't, output 'None' --> <xsl:otherwise>None</xsl:otherwise> </xsl:choose> </p> </xsl:for-each> <!-- end for-each Component_Context --> <!-- current node = Component --> <!-- 2. *** Find all the sub-Components ordered by decomposition ***** --> <!-- define a variable expansions to contain the Expansions for the current Component --> <xsl:variable name="expansions" select="key('expansion-name', Component_Core/@Name)" /> SubComponents = <xsl:choose> <!-- if there are any expansion... --> <xsl:when test="$expansions"> <ul> <!-- go through the expansion one by one (document order) --> <xsl:for-each select="$expansions"> <!-- current node = an Expansion --> <li> <xsl:for-each select="Element[key('Component-Component_context_id',@id)/Component_Core/@Na me]"> <!-- current node = a Element --> <xsl:sort select="key('Component-Component_context_id',@id)/Component_Core/@Name"/> <a href = "#{generate-id(key('Component-Component_context_id',@id))}"> <xsl:value-of select="key('Component-Component_context_id',@id)/Component_Core/@Name" /> </a> <xsl:if test="position() != last()">, </xsl:if> </xsl:for-each> <!-- end for-each Element--> </li> </xsl:for-each> <!-- end for-each $expansions--> <!-- Display the image because there is a decomposition --> <p> <img src="{$ComponentName}.png"/> </p> </ul> </xsl:when> <!-- if there aren't, output 'None' --> <xsl:otherwise>None</xsl:otherwise> </xsl:choose> <hr></hr> </xsl:for-each> <!-- end for-each Component --> </xsl:template> <xsl:template match="*"> <!-- do nothing --> </xsl:template> </xsl:stylesheet> -------an extract of XML file--- <?xml version="1.0" encoding="UTF-8"?> <!-- Document type definition (external) --> <!DOCTYPE Card SYSTEM "Components.dtd"> <Card Version="V.2.0"> <Components_Elements> <Component> <Component_Core Name="A" > <Semantics>Semantics for A</Semantics> </Component_Core> <Component_Context id="_2" > <Precondition>precondition for A</Precondition> <Feedback>feedback for A</Feedback> <Postcondition></Postcondition> </Component_Context> </Component> <Component> <Component_Core Name="A1" > <Semantics>do something</Semantics> </Component_Core> <Component_Context id="_5" > <Precondition></Precondition> <Feedback></Feedback> <Postcondition></Postcondition> </Component_Context> </Component> <Boolean_Connector Name="Bool.C. " id="_14" ></Boolean_Connector> <Boolean_Connector Name="Bool.C. 0" id="_17" ></Boolean_Connector> <Link id="_7" Parent_Component_Name="A" id1="_5" id2="_6"> <Precondition></Precondition> </Link> <Link id="_15" Parent_Component_Name="C" id1="_14" id2="_12"> <Precondition></Precondition> </Link> </Components_Elements> <Components_Decomposition> <Expansion Component_Name="A"> <Element id="_5" X="68.0" Y="43.0"></Element> <Element id="_6" X="101.0" Y="163.0"></Element> </Expansion> </Components_Decomposition> </Card> 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
|