Nisar
Nisar

Reputation: 6038

xslt value of in an ID or Class element

Trying to get value of xml in ID element in a div..

<xsl:for-each select="tables">
    <xsl:for-each select="table">
        <xsl:for-each select="@name">
            <div id="<xsl:value-of select="."/>">

            </div>
        </xsl:for-each>
    </xsl:for-each>
</xsl:for-each>

I know this is wrong .. need help how to do it properly


Input XML

<?xml-stylesheet type="text/xsl" href="ddlms.xslt"?>
<tables>
<table name="tbl_AccountLedger">
 <row>
        <Field></Field>
        <ColumnName>ledgerId</ColumnName>
        <DataType>varchar</DataType>
        <Prec tbl="krishna">50</Prec>
        <Cons>PK</Cons>
        <Ref></Ref>
        <Coded></Coded>
        <Def></Def>
        <Description></Description>
 </row>
 </table>
 </tables>

Upvotes: 1

Views: 4224

Answers (3)

user3673263
user3673263

Reputation:

replace <div id="<xsl:value-of select="."/>"> with <div id="{.}">

and watch the miracle happen.

Upvotes: 3

michael.hor257k
michael.hor257k

Reputation: 116959

Try something like:

<xsl:template match="/">
    <root>
        <xsl:for-each select="tables/table">
            <div id="{@name}">

            </div>
        </xsl:for-each>
    </root>
</xsl:template>

Upvotes: 1

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

try this stylesheet:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:strip-space elements="*"/>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="tables">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="table">
        <div id="{@name}">

        </div>
    </xsl:template>

</xsl:stylesheet>

try to have a read regarding attribute value templates (http://www.w3.org/TR/xslt#attribute-value-templates).

Upvotes: 1

Related Questions