Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xslt add value to attribute list

Status
Not open for further replies.

fostom

Programmer
Jul 3, 2002
31
NO
Hi.

Can anyone help me with this xslt problem? I have this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<Bilder>
<Bild url=" ordning="0" mediatypid="1">
tullball
</Bild>
</Bilder>

..and I want convert it to this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<Bilder>
<Bild url=" ordning="0" mediatypid="1" value="tullball">
</Bild>
</Bilder>

..can anyone help me with the look of the xslt?

Regards, Tommy
 
You need to supply more information. Will there be multiple <Bild> nodes and do you want to add it to all? Where does value come from? etc. For instance, you could use this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="/">
    <Bilder>
      <Bild url="[URL unfurl="true"]http://picsrv.annons.dn.se/bsbilder/1/31169/1_31169_31169-679119660_680707379.jpg"[/URL] ordning="0" mediatypid="1" value="tullball"/>
    </Bilder>
  </xsl:template>
</xsl:stylesheet>
But you probably want something more like:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="bild">
    <xsl:copy>
      <xsl:attribute name="value">tullball</xsl:attribute>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
This is what I meant:

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl=" version="1.0"><xsl:eek:utput method="xml"/>
<xsl:template match="/">
<xsl:element name="images">
<xsl:for-each select="/Bilder/Bild">
<xsl:for-each select="*" >
</xsl:for-each>
<xsl:element name='image'>
<xsl:attribute name="thumb"><xsl:value-of select="@url"/></xsl:attribute>
<xsl:attribute name='value'> <xsl:value-of select="."/></xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

..I pulled it together after a couple of hours.. xslt is not fun :(

Thanks for trying to help me!

Tommy
 
Simpler would be:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
  <xsl:output method="xml"/>
  <xsl:template match="/">
    <images>
      <xsl:apply-templates select="/Bilder/Bild"/>
    </images>
  </xsl:template>
  <xsl:template match="Bild">
    <image thumb="{@url}" value="{.}"/>
  </xsl:template>
</xsl:stylesheet>

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top