Hi to all!

I am pretty new to Xpath and I am quite lost.
I use Stylus Studio Prof for all things related to XML, and I've been struggling with this apparently simple question for a few days.

If I have something like:

<sales>
  <person>
    <id>
      <tag>2345X</tag>
      <name>Doe, Joe</name>
    </id>
    <amount>444.60</amount>
  </person>
  <person>
    <id>
      <tag>9874A</tag>
      <name>One, Any</name>
    </id>
    <amount>673.98</amount>
  </person>
  <person>
    <id>
      <tag>4561C</tag>
      <name>Ine, Carol</name>
    </id>
    <amount>8765.00</amount>
  </person>
</sales>

(In fact I'm working with a much more complex structure...)

I know how to get all <tag>'s and how to get all <amount>'s, but is there a (simple) way to get the following, with a one-liner?

2345X 444.60
  9874A 673.98
  4561C 8765.00

That is, a list of <tag>'s and the corresponding <amount> for each person.

Thanks a lot for your help.

JotaPe

There is no such thing as an XSLT oneliner :-)

This should work for you however

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" />

<xsl:template match="person">
   <xsl:value-of select="./id/tag" />
   <xsl:text>  </xsl:text>
   <xsl:value-of select="amount" />
   <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="sales">
    <xsl:apply-templates select="person" />
</xsl:template>

</xsl:stylesheet>

Thanks a lot, fpmurphy!

That does it... and it opens the way to the solution of my real problem.
I am dealing with ONIX for Books records, which are a _bit_ more complex than the example, but your proposal is easily extensible.

Of course when I mentioned a "one-liner xPath", I was thinking about a "few-liner solution"!

Best regards to all.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
	<xsl:template match="/">
		<xsl:apply-templates select="sales/person"/>
	</xsl:template>


	<xsl:template match="person">
	<xsl:value-of select="concat(id/tag,'        ',amount,'&#xA;')"/>
	</xsl:template>
</xsl:stylesheet>
This article has been dead for over six months. Start a new discussion instead.