I want my xpath query to return something like:
customerName=...
id=...
customField=....

regardless whether those nodes exist in my xml:

<Begin>
<CustomerRet>
<customerName>Jack</customerName>
<customerId>1</customerId>
<customField>A</customField>
</CustomerRet>

<CustomerRet>
<customerName>Jack</customerName>
<customerId>1</customerId>
</CustomerRet>
</Begin>

How do I go about writing my expression? I tried using concat but it's not working for me.

/Begin/CustomRet/concat('customerName=',customerName) | /Begin/CustomRet/concat('customId=',customerId) | /Begin/CustomRet/concat('customField=',customField)

Recommended Answers

All 2 Replies

<?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="CustomerRet">
  customerName=<xsl:value-of select="./customerName"/>
  id=<xsl:value-of select="./customerId"/>
  customeField=<xsl:value-of select="./customField"/>
</xsl:template>

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

</xsl:stylesheet>

Here is the output for the example xml file you supplied

customerName=Jack
  id=1
  customeField=A


  customerName=Jack
  id=1
  customeField=

with xquery

let $doc := doc("begin.xml")
for $x in $doc/Begin/CustomerRet

return concat(concat("Name   ", $x/customerName,"&#xA;"), concat("id     ",$x/customerId,"&#xA;"),concat("Field  ",$x/customField,"&#xA;"))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.