<xsl:transform version="2.0"
    xmlns:po="http://www.w3.org/2002/ws/sawsdl/spec/examples/wsdl/PurchaseOrderService#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sp="http://www.w3.org/2005/sparql-results#">

  <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes" />
  <xsl:template match="/sp:sparql">
    <po:OrderRequest>
        <xsl:variable name="fullName">
          <xsl:value-of select="sp:results/sp:result[position()=1]/sp:binding[@name='name']/sp:literal"/>
        </xsl:variable>
        <po:firstinitial>
          <xsl:value-of select="substring(substring-before($fullName,' '),1,1)" />
        </po:firstinitial>
        <po:lastName>
          <xsl:value-of select="substring-after($fullName,' ')" />
        </po:lastName>
      <xsl:apply-templates select="sp:results/sp:result" />
    </po:OrderRequest>
    </xsl:template>
    <xsl:template match="sp:result">
    <po:item>
      <po:itemCode>
        <xsl:value-of select="sp:binding[@name='partNum']/sp:literal" />
      </po:itemCode>
      <po:quantity>
          <xsl:value-of select="sp:binding[@name='quantity']/sp:literal" />
      </po:quantity>
      <po:dueDate>
        <xsl:value-of select="sp:binding[@name='dueDate']/sp:literal" />
      </po:dueDate>
      <po:billingInfo>
        <xsl:value-of select="sp:binding[@name='billingInfo']/sp:literal" />
      </po:billingInfo>
    </po:item>
  </xsl:template>
</xsl:transform>
</lowering>
