xml - What does it mean apply-templates select='*'? -
forgive me learned xsl
, , have trouble understand apply-templates well. in understanding. apply-templates
find nodes match select
. , search in current xsl document if there template
defined specified select nodes. apply style these nodes.
for example:
<catalog> <cd> <title>empire burlesque</title> <artist>bob dylan</artist> <country>usa</country> <company>columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>hide heart</title> <artist>bonnie tyler</artist> <country>uk</country> <company>cbs records</company> <price>9.90</price> <year>1988</year> </cd> <cd> <title>greatest hits</title> <artist>dolly parton</artist> <country>usa</country> <company>rca</company> <price>9.90</price> <year>1982</year> </cd> </catalog> <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <h2>my cd collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> <xsl:template match="title"> title: <span style="color:#ff0000"> <xsl:value-of select="."/></span> <br /> </xsl:template> <xsl:template match="artist"> artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template> </xsl:stylesheet>
- the first apply-templates in
<xsl:template match="/">
, means nodes under rootcatalog
apply specified template. since there template defined these nodes. apply template these nodescd
. , other apply-templates. works same rule.
but when see xsl below. there cruisecontrol.net mstestreport2010.xsl
<xsl:variable name="runinfos" select="*[local-name()='resultsummary']/*[local-name()='runinfos']/*[local-name()='runinfo']" /> <xsl:if test="count($runinfos) > 0"> <h3>errors , warnings</h3> <table width="100%" border="1" cellspacing="0" style="font-size:small;"> <xsl:apply-templates select="$runinfos" /> </table> </xsl:if>
in understanding xsl:apply-templates select="$runinfos"
search xsl document find template defined it. below.
<xsl:template match="*[local-name()='runinfo']"> <tr> <td> <xsl:apply-templates select="*" /> </td> </tr> </xsl:template>
but make me confused mean select="*"
. because seach in xsl document .found there not such *
template defined ..
and wonder question : if there no template match selected nodes in xsl:apply-templates
?
and how can test , debug xsl in tools . please share me if have ones.thanks.
here xml
<cruisecontrol project="kmimproject"> <build date="2015-10-09 19:01:32" buildtime="00:00:35" error="true" buildcondition="forcebuild"> <testrun id="1bd2dff0-7418-4a1e-8ffd-189b27d1b118" name="administrator@joe-wangpc 2015-10-09 19:01:26" runuser="joe-wangpc\administrator" xmlns="http://microsoft.com/schemas/visualstudio/teamtest/2010"> <testsettings name="default test settings" id="6e1f3ea2-9cf0-4beb-8305-1a4b5db1fa55"> <deployment userdeploymentroot="e:\study\cc.net\test\kmih\workingfolder" usedefaultdeploymentroot="false" rundeploymentroot="administrator_joe-wangpc 2015-10-09 19_01_26"/> <execution> <testtypespecific/> <agentrule name="execution agents"> </agentrule> </execution> <properties/> </testsettings> <times creation="2015-10-09t19:01:26.3934012+08:00" queuing="2015-10-09t19:01:26.6424154+08:00" start="2015-10-09t19:01:26.7014188+08:00" finish="2015-10-09t19:01:27.1244430+08:00"/> <resultsummary outcome="failed"> <counters total="106" executed="59" error="0" failed="59" timeout="0" aborted="0" inconclusive="0" passedbutrunaborted="0" notrunnable="47" notexecuted="0" disconnected="0" warning="0" passed="0" completed="0" inprogress="0" pending="0"/> <runinfos> <runinfo computername="joe-wangpc" outcome="warning" timestamp="2015-10-09t19:01:26.4934069+08:00"> <text>warning: test run deployment issue: assembly or module 'kmih.persistence' directly or indirectly referenced test container 'e:\study\cc.net\test\kmih\sourcecheckoutfolder\kmih.unittests\obj\release\kmih.unittests.dll' not found.</text> </runinfo> <runinfo computername="joe-wangpc" outcome="warning" timestamp="2015-10-09t19:01:26.4934069+08:00"> <text>warning: test run deployment issue: assembly or module 'kmih.webui' directly or indirectly referenced test container 'e:\study\cc.net\test\kmih\sourcecheckoutfolder\kmih.unittests\obj\release\kmih.unittests.dll' not found.</text> </runinfo> </runinfos> </resultsummary> </testrun> </build> </cruisecontrol>
it means "select element children , apply templates match them." if there is, example, child tag meh
, template element matching meh
(or more general match), apply template child element. apply-templates
not choose template, tells engine templates should applied selection (in select
attribute) , engine should find appropriate templates them.
if there no template matching element, xslt has built-in rules "apply templates child elements also, , if there text nodes, copy them output". in case since elements inside runinfo have no matching template, xslt copy text inside output.
Comments
Post a Comment