xslt - XPath testing attributes of different paths against eachother -
i have these xml files:
include_paths.xml
<includes> <include name="foo" path="path/to/foo"> <include name="bar" path="path/to/bar"> </includes>
main.xml
<model> <include file="foo"> <include file="bar"> </model>
xslt stylesheet (sheet.xslt)
<xsl:param name="include_paths"/> <xsl:template match="/"> <ul> <xsl:apply-templates select="//include"/> </ul> </xsl:template> <xsl:template match="include"> <li><a href="#{document($include_paths)/includes/include[@name = @file]/@name}"><xsl:value-of select="@file"/></a></li> </xsl:template>
i run transformation with
xsltproc --stringparam include_paths include_paths.xml sheet.xslt main.xml
what code supposed first give script parameter containing file path of include_paths.xml
defines include paths. parameter declared globally , used in "include" template. when iterating through includes main.xml
, want put in <a>
tag linking path name matches in include tags different xml files.
so example, want <li>
item ends <include>
item main.xml
@file=foo
have path path/to/foo
, taken include_paths.xml
. produce following expected result:
<ul> <li><a href="path/to/foo">foo</a></li> <li><a href="path/to/bar">bar</a></li> </ul>
i think problem namespacing (scoping?) in xpath expression, can't distinguish @name
, @file
tags. guess scope of document(...)
function of $include_paths
variable , hence include_paths.xml
file, problem how refer @file
attribute xpath expression.
how solve problem?
use current()
in <a href="#{document($include_paths)/includes/include[@name = current()/@file]/@name}"><xsl:value-of select="@file"/></a>
.
Comments
Post a Comment