Retrieve all the attribute values from XML using XSLT -


i can't figure out how access attributes in tag xml document.

let's have following xml:

<names>   <name firstname="rocky" lastname="balboa" divider=", "/>   <name firstname="ivan" lastname="drago" divider=", "/> </names> 

i want following output: rocky balboa, ivan drago,

what have is:

<xsl:for-each select="names/name">    <xsl:value-of select="@firstname"/>    <xsl:value-of select="@lastname"/>    <xsl:value-of select="@divider"/> </xsl:for-each> 

what i'm wondering if it's possible in 1 value-of select instead of having 3 of them. clarify, want able output attributes in tag 1 single value-of select. possible?

thanks.

because i'm not sure if use of xsl:value-ofis hard requirement, perhaps following locking for.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output indent="yes"/>      <xsl:template match="name" mode ="print" >         <xsl:value-of select="@firstname"/>         <xsl:text> </xsl:text>         <xsl:value-of select="@lastname"/>         <xsl:value-of select="@divider"/>     </xsl:template>      <xsl:template match="/">         <xsl:apply-templates  select="names/name" mode="print"/>     </xsl:template>  </xsl:stylesheet> 

you can use <xsl:apply-templates select="names/name" mode="print"/> @ position have considered using 1 line value-of attributes.
above template generate following output:

rocky balboa, ivan drago, 

update crate output without using attribute names:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output indent="yes"/>      <xsl:template match="name" mode ="print" >         <xsl:for-each select="@*" >             <xsl:if test="not(position() = last() or position() = 1)">                 <xsl:text> </xsl:text>             </xsl:if>             <xsl:value-of select="."/>          </xsl:for-each>     </xsl:template>      <xsl:template match="/">         <xsl:apply-templates  select="names/name" mode="print"/>     </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -