Showing posts with label XSLT. Show all posts
Showing posts with label XSLT. Show all posts

Saturday, June 16, 2012

Upper case to lower case and lower case to upper case in XSLT

Here i will show how to cover the lower case characters to upper case and upper case characters to lower case in xslt.There simple way i have used to create variable for both lower and upper letters ,then URL string replace will be done using those variable
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
    <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
    <xsl:template match="/">
        <xsl:variable name="PUrlLower" select="translate($PUrl, $ucletters, $lcletters)">
        </xsl:variable>
         <a>
           <xsl:attribute name="href">
                <xsl:value-of select="$PUrl"/>
            </xsl:attribute>
            <xsl:attribute name="title">
                <xsl:value-of select="$PTitle"/>
            </xsl:attribute>
            <xsl:value-of select="$PTitle"/>
        </a>
        </xsl:template>
</xsl:stylesheet>

Saturday, May 12, 2012

convert uppercase to lowercase in xslt


Here i will show how to translate the uppercase letter to lowercase using xslt.For this i have created a variables ,which are used in this conversion process.Then the result will be assigned to one parameter which is "purl".
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="CurrentUrl"></xsl:param>
    <xsl:param name="PUrl"></xsl:param>
    <xsl:variable name="lowercletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
    <xsl:variable name="uppercletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> 
    <xsl:template match="/">
        <xsl:for-each select="/Item/Menu">
            <xsl:if test="$PUrl = translate(Link, $uppercletters, $lowercletters)">
                <h1>
                    <xsl:value-of select="item"/>
                </h1>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Sunday, April 29, 2012

How the item is active based on position in xml using xslt

Here i will show how to create position  based div's from XML data source using xslt.The XML data source has parent attribute with three items .There is on click function to make the selected div as active .By default we will set the first items as active link

<?xml version="1.0" encoding="utf-8" ?> 
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="/">
<div>
- <ul>
- <xsl:for-each select="Menu/Item">
- <xsl:if test="ItemType != 'Javascript'">
- <li>
- <xsl:if test="position() = 1">
- <xsl:attribute name="class">
  <xsl:text>active</xsl:text>
  </xsl:attribute>
  </xsl:if>
- <a title="" onclick="return false;">
- <xsl:attribute name="href">
- <xsl:choose>
- <xsl:when test="position() = 1">
  <xsl:text>#stories</xsl:text>
  </xsl:when>
- <xsl:when test="position() = 2">
  <xsl:text>#events</xsl:text>
  </xsl:when>
- <xsl:when test="position() = 3">
  <xsl:text>#news</xsl:text>
  </xsl:when>
  </xsl:choose>
  </xsl:attribute>
  <xsl:value-of select="ItemTitle" />
  </a>
  </li>
  </xsl:if>
  </xsl:for-each>
  </ul>
</div>
  </xsl:template>
  </xsl:stylesheet>

Wednesday, April 25, 2012

How to Get all xml Items using xslt

Before doing this task i don't have an idea about xslt .Xslt is easy to learn and  to develop. Here i will show how to get the all XML items and display the items as list of anchor at client side view.For this i will use for loop to get the XML data

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">  
    <xsl:template match="/">
        <xsl:for-each select="List/Item">           
                <a>
                    <xsl:attribute name="href">
                        <xsl:text>#</xsl:text>
                    </xsl:attribute>
                    <xsl:attribute name="title">
                        <xsl:text>Title</xsl:text>
                    </xsl:attribute>
                    <xsl:attribute name="target">
                        <xsl:text>blank</xsl:text>
                    </xsl:attribute>                   
                    <img>
                        <xsl:attribute name="src">
                            <xsl:value-of select="href"/>
                        </xsl:attribute>
                        <xsl:attribute  name="alt">
                            <xsl:value-of select="Title"/>
                        </xsl:attribute>
                        <xsl:attribute  name="class">
                            <xsl:text>slider_img</xsl:text>
                        </xsl:attribute>
                    </img>
                    <span>
                        <b>
                            <xsl:value-of select="Title"/>
                        </b>                       
                        </span>
                </a>               
        </xsl:for-each>    </xsl:template>  
</xsl:stylesheet>

Bel