Xslt using a wildcard when selecting by attribute
so I have this assignment and they are asking for data given by Xslt
This is what I've got:
<xsl:apply-templates开发者_StackOverflow社区 select="results/result[@name=$param0]"/>
So the $param0 is given by a jquery transform function. My problem is how can I select all of the @name when sending a certain value for $param0? I've tried most wildcards but nothing seems to work. Can you guys help me?
input XML
<results>
<result name="name1">
<score>2500</score>
</result>
<result name="name2">
<score>13500</score>
</result>
<result name="name3">
<score>65100</score>
</result>
</results>
output for $param0="name1"
<result name="name1">
<score>2500</score>
</result>
So i would have to get all of the scores, I need to keep the xslt statement so I can still select one.
output for $param0="wildcard" <== I need some kind of wildcard (have tried alot of them)
<result name="name1">
<score>2500</score>
</result>
<result name="name2">
<score>13500</score>
</result>
<result name="name3">
<score>65100</score>
</result>
I hope this makes a it clearer what I'm looking for...
Why not using a fake string wildcard?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="param0" select="'*'"/>
<xsl:template match="/">
<xsl:copy-of select="results/result[@name=$param0 and $param0!='*']
|
results/result[$param0='*']"/>
</xsl:template>
</xsl:stylesheet>
It copies every result when $param0='*'
, otherwise it copies the wanted node when there is a match like $param0='name1'
; otherwise it does not copy anything at all.
You can use the same expression within xsl:apply-templates
.
精彩评论