Quantcast
Channel: Using XSLT to transform XML to XML - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by michael.hor257k for Using XSLT to transform XML to XML

$
0
0

I think this may do what you described. At least the result received is the same as the desired one, AFAICT:

XSLT 1.0

<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/><xsl:strip-space elements="*"/><xsl:template match="/courses"><classes count="{count(course/section[@delivery='Classroom'])}"><xsl:apply-templates select="course/section[@delivery='Classroom']"><xsl:sort select="enrollment" data-type="number" order="ascending"/></xsl:apply-templates></classes></xsl:template><xsl:template match="section"><class credits="{../@credits}" room="{room}"><number><xsl:value-of select="../@number"/></number><xsl:copy-of select="../title | enrollment | instructor"/></class></xsl:template></xsl:stylesheet>

I'd also like to avoid using <xsl:for-each> as I've heard it is bad to use.

Don't believe all you hear. As it happens, it's not convenient to use it here, but I would not hesitate to use it otherwise.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>