Jump to content

XSLT - for-each and value-of

Guest nivedan

Recommended Posts

Hi everyone,Objective: To use XSLT to check if an input element contains a valid value and then map it to the output. In the example below I try to print the value.I want to read this xml file and then in a for loop want to check ifthe element myImage is a valid one and print that value.For example: IF the element myImage was blank </myImage> then I want to skip it and read the next until all such elements are read.At the moment I get blank when it iterates through the loop. It does get into the loop. Could someone let me know how I can resolve this?Thank youThe xml file as below.<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="catalog.xsl"?><mycatalog> <cd> <title>XSLT Transformers</title> <artist>Some artist</artist> <age>80</age> <myImage>32</myImage> <myImage>33</myImage> <myImage>34</myImage> <myImage>35</myImage> <myImage>36</myImage> </cd></mycatalog>The XSLT is as follows<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" indent="yes" /><xsl:template match="/"><cdcatalogs> <xsl:for-each select="mycatalog/cd"> <cd> <title><xsl:value-of select="title"/></title> <artist><xsl:value-of select="artist"/></artist> <age><xsl:value-of select="age"/></age> <xsl:for-each select="myImage"> <myImage><xsl:value-of select="myImage"/></myImage> </xsl:for-each> </cd> </xsl:for-each> </cdcatalogs></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...