XSLT select part of XML message -


i'm strugling find solution xml message extract problem. have similar below xml message:

<orders xmlns="http://au.inputorders"> <order> <orderref>d04004451</orderref> <orderqty>5</orderqty> </order> <order> <orderref>d04004451</orderref> <orderqty>1</orderqty> </order> <order> <orderref>d04004452</orderref> <orderqty>1</orderqty> </order> <order> <orderref>d04004452</orderref> <orderqty>4</orderqty> </order> <order> <orderref>d04004452</orderref> <orderqty>2</orderqty> </order> </orders> 

i need xslt bit only:

<orders xmlns="http://au.inputorders"> <order> <orderref>d04004451</orderref> <orderqty>5</orderqty> </order> <order> <orderref>d04004451</orderref> <orderqty>1</orderqty> </order> </orders> 

and

<orders xmlns="http://au.inputorders"> <order> <orderref>d04004452</orderref> <orderqty>1</orderqty> </order> <order> <orderref>d04004452</orderref> <orderqty>4</orderqty> </order> <order> <orderref>d04004452</orderref> <orderqty>2</orderqty> </order> </orders> 

in other words, need retrieve order parts based on orderref element value.

thanks.

tried both below solution , both works. did find solution works well. doesn't use orderref position of order elements. still 1 doing needed.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"  xmlns:ns0="http://au.inputorders"> <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="no"/> <xsl:template match="/">    <xsl:element name="orders" namespace="http://au.inputorders">    <xsl:copy-of select="ns0:orders/ns0:order[position() &gt;= 1 , position() &lt;=2]"/>    </xsl:element> </xsl:template> </xsl:stylesheet> 

thanks.

here's simple stylesheet you're asking. (it's using default value parameter, can overriden.)

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"     xmlns:au="http://au.inputorders">     <xsl:output indent="yes"/>     <xsl:strip-space elements="*"/>      <xsl:param name="orderref" select="'d04004451'"/>      <xsl:template match="/*">         <xsl:copy>             <xsl:copy-of select="au:order[au:orderref=$orderref]"/>                  </xsl:copy>     </xsl:template>  </xsl:stylesheet> 

if need additional processing, replace xsl:copy-of xsl:apply-templates, add identity transform, , override templates handle specific pieces.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -