xsl-list
[Top] [All Lists]

[xsl] Relative/Absolute path queries?

2008-12-11 05:30:55
Hi,

I have an another question:

Assume:

<?xml version="1.0" encoding="UTF-8"?>
<demo>
        <library><books><book title="test" key="1"/></books></library>
        <stock><quantity key="1">50</quantity></stock>
</demo>

Questions (see my first try below):

1. How can I print the quantity of the book while looping books? Or better:
        - How do I print quantity by absolute path (below I assume filesystem
style '/demo/stock/@quantity[(_at_)key=(_dot_)(_dot_)(_dot_)]')
        - How do I print quantity by relative path (e.g. filesystem style
while in Book: './../../stock/quantity[(_at_)key=(_dot_)(_dot_)(_dot_)]')

2. I now need an empty template (see last line) demo/stock to suppress
output which doesn't match any template. How can I create 1 template
for all nodes which don't mach? This avoid me creating a lot of empty
templates for every not output generating node.


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="demo/library/books">
        <xsl:for-each select="book">
             Title: <xsl:value-of select="@title"/>
             <xsl:variable name="keyCurrentBook" select="@key"/>
             Quantity: <xsl:value-of
select="/demo/stock/@quantity[(_at_)key=$keyCurrentBook]"/>
        </xsl:for-each>
</xsl:template>
<xsl:template match="demo/stock"/>
</xsl:stylesheet>


Thank you

Peter

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>