Global GuideLine Home HTML Tutorial JavaScript Tutorial SQL Tutorial CSS Tutorial SEO Tutorial XML Tutorial XSLT Tutorial Articles Tutorial Interview Questions and Answers Guide Jobs GuideLine Bookmark With Google Bookmark With Yahoo Bookmark With FaceBook Bookmark With Live Follow @GlobalGuideLine on Twitter Bookmark Global GuideLine
XSLT Multi Selection, XSLT Tutorial, Global Guideline

Bookmark this webpage. Bookmark: XSLT Multi Selection, XSLT Tutorial Global Guideline is UNITED STATES's favorite website


      Home                    

Basic XSLT Tutorial.     
 XSLT Introduction.          
 XSLT Templates.            
 XSLT Attributes.              
 XSLT Transformation.     
 XSLT Variables.              
 XSLT Formatting.            
 XSLT Loops.                   
 XSLT Sorting.                 
 XSLT Conditions.             
 XSLT Multi Selection.
 XSLT Functions.              
 XSLT Copying.                
 XSLT Combining.           
 XSLT Summary.              

XSLT Tutorial >> XSLT Multi Selection.


     Back             Next     



XSLT Multi Selection is use to convert multiple XML elements to a values for a single attribute. Here is the information about how this can be done with XSLT multi selection.

<!--XML structure for XSLT Multi Selection in XSLT Tutorial-->
<WebPage>
 <Head>
  <Title>XSLT Tutorial at Global Guide Line</Title>
  <MainCategory></MainCategory>
  <Keyword>XSLT Tutorial</Keyword>
  <Keyword>XSLT Function</Keyword>
  <Keyword>XSLT Transformation</Keyword>
 </Head>
 <Body>
 </Body>
 <Info>
 </Info>
</WebPage>

From the above source elements <Keyword> should be converted to the below result.

<META name="keywords" content="XSLT Tutorial, XSLT Function, XSLT Transformation">

All above is done with this XSLT transformation

Converting Multiple Elements To One Attribute In XSLT Multi Selection.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--Exampleof XSLT Multi Selection in XSLT Tutorial-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
  <xsl:template match="/">
  <HTML>
  <HEAD>
    <xsl:element name="META">
    <xsl:attribute name="name">keywords</xsl:attribute>
    <xsl:attribute name="content">
      <xsl:for-each select="WebPage/Head/Keyword">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">, </xsl:if>
      </xsl:for-each>
    </xsl:attribute>
    </xsl:element>
    <TITLE>
    </TITLE>
  </HEAD>
  <BODY></BODY>
  </HTML>
  </xsl:template>
</xsl:stylesheet>



<xsl:element> and <xsl:attribute> on above code allows dynamic creation of elements and attributes. <xsl:element name="META"> defines the element of <META>. and <xsl:attribute name="name"> keywords</xsl:attribute> results as <META name="keywords"> on output.  The content of the attribute content on above code is created dynamically with a selection of each <WebPage><Head><Keyword> element, and in between of these values a semicolon is added. <xsl:if test=position() != last()"> checks if the <Keyword> element was not the last one, as with the last one no more semicolon is used.

<xsl:template match="/">
<HTML>
  <HEAD>
    <META name="keywords">
      <xsl:attribute name="Content">
        <!--Applying template below this section of code-->
        <xsl:apply-templates select="WebPage/Head/Keyword" />
      </xsl:attribute>
    </META>
    <TITLE>
    </TITLE>
  </HEAD>
  <BODY></BODY>
</HTML>
</xsl:template>

<xsl:template match="WebPage/Head/Keyword" >
  <!--Use of xsl-value in XSLT Multi Selection-->
  <xsl:value-of select="."/>
  <!--If condition use in XSLT Multi Selection Example-->
  <xsl:if test="following-sibling::Keyword">,</xsl:if>
</xsl:template>

     Back             Next     
 
In order to link this page as Reference, click on below text area and pres (CTRL-C) to copy the code in clipboard or pres right click then copy the following lines after that past into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code:

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright © 2005-2006 www.globalguideline.com All rights reserved. Join Global Guide Line community. 829 visitors are online now