xsl-list
[Top] [All Lists]

Re: Help with the xsl stylesheet to create attribute as element and group

2005-05-04 03:46:14
Please try this XSL..

(I think this is not a efficient algorithm. You may
use Muenchian grouping if you need better
performance..)

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 
<xsl:output method="xml" indent="yes" /> 

<xsl:template match="/">
 <Unit xmlns="http://www.xml.com/xml/unit";
        
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        
xsi:schemaLocation="http://www.xml.com/xml/unit/unit.xsd";>
     <Objectives>
       <xsl:for-each select="//*[local-name() =
'Objective'][not(@domain =
preceding-sibling::*[local-name() =
'Objective']/@domain)]">  
          <xsl:variable name="temp" select="@domain"
/>
          <xsl:element name="{(_at_)domain}">
            <xsl:for-each select="//*[local-name() =
'Objective'][(_at_)domain = $temp]">
              <xsl:copy>
                <xsl:value-of select="." />
              </xsl:copy>
            </xsl:for-each>
          </xsl:element>
       </xsl:for-each>
     </Objectives>
  </Unit>
</xsl:template>
 
</xsl:stylesheet>

Regards,
Mukul

--- Seng Kiat Lim <limsengkiat83(_at_)hotmail(_dot_)com> wrote:

I wish to produce a xml output from unitplanning xml
document using an xsl 
stylesheet. I am new to it so has no idea how to
group the domain and the 
objective under the domain.

unitPlanning.xml
<Unit xmlns="http://www.xml.com/xml/unit";

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.xml.com/xml/unit
unit.xsd">
<Objectives>
<Objective domain="CognitiveDomainObjective">an
understanding of the roles 
of XML in providing IT solutions to
organization</Objective>
<Objective domain="CognitiveDomainObjective">the
knowledge of XML 
technologies components and their roles in providing
XML solution to IT and 
business problems</Objective>
<Objective domain="CognitiveDomainObjective">the
knowledge of the specific 
issues and requirements related to the field of XML
technologies,in 
particular XML document, DTD, XML Schema, XPath and
XSLT</Objective>
<Objective domain="CognitiveDomainObjective">an
understanding of the 
different issues related to storing and retrieving
textual data</Objective>
<Objective domain="CognitiveDomainObjective">an
understanding of the 
different design and implementation issues related
to search 
engines</Objective>
<Objective domain="AffectiveDomainObjective">an
appreciation of the role of 
XML technologies as a solution to some of the
distributed computing,WWW and 
database problems</Objective>
<Objective domain="AffectiveDomainObjective">an
acceptance that XML 
technology has its own limitation and it should be
considered when 
developing a solution</Objective>
<Objective domain="AffectiveDomainObjective">an
appreciation of the role of 
DTD and XML Schema in ensuring the quality of the
XML solution</Objective>
<Objective domain="AffectiveDomainObjective">an
appreciation of the 
complexity inherent by text retrieval
systems</Objective>
<Objective
domain="PsychomotorDomainObjective">designing and
creating a 
well-formed and valid XML document</Objective>
<Objective
domain="PsychomotorDomainObjective">retrieving and
transforming 
XML document into a number of different presentation
format</Objective>
<Objective
domain="PsychomotorDomainObjective">identifying
different 
components of a text retrieval system</Objective>
<Objective
domain="PsychomotorDomainObjective">evaluating the
different 
techniques used in building a text retrieval
systems</Objective>
</Objectives>
</Unit>

Xslt stylesheet:
<xsl:element name="Objectives">
<xsl:element

name="{unit:Unit/unit:Objectives/unit:Objective/@domain}">
<xsl:element name="Objective">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>

</xsl:element>


Expected output from unitPlanning.xml using
stylesheet

<Unit xmlns="http://www.xml.com/xml/unit";

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.xml.com/xml/unit
newUnit.xsd">
<Objectives>
<CognitiveDomainObjective>
<Objective>...
</Objective>
<Objective>....
</Objective>
<Objective>.....
</Objective>
</CognitiveDomainObjective>
<AffectiveDomainObjective>
<Objective>...
</Objective>
</AffectiveDomainObjective>
<PsychomotorDomainObjective>
<Objective>.....
</Objective>
</PsychomotorDomainObjective>
</Objectives>
</Unit>

At the same time, I also wish to refer to a new
schema in the stylesheet and 
I also wish to know how to do it. I need to produce
the XML file that looks 
like this which could be valid in my schema.I have
read the grouping using 
the stylesheet but it does not seem working. So, can
anyone there pls help 
me out with this?




--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>