Altova Mailing List Archives


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

From: Mukul Gandhi <mukul_gandhi@--------->
To:
Date: 5/4/2005 10:47:00 AM
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="{@domain}">
            <xsl:for-each select="//*[local-name() =
'Objective'][@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@xxxxxxxxxxx> 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?
> 
> 


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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.