xml - XSLT: Get previous node value within text tokenized template -


i'm new in xslt hope i'll here.

i'm trying transform following xml

<?xml version="1.0"?><?xml-stylesheet type="text/xsl"?>     <orderlineitems>     <orderlineitem>         <sku>60</sku>         <meta>topic: one, topic: two, topic: three, topic: four</meta>     </orderlineitem>     <orderlineitem>         <sku>70</sku>         <meta>topic: one, topic: two, topic: three, topic: four</meta>     </orderlineitem>     </orderlineitems> 

to

<articleno>60.1</articleno> <articleno>60.2</articleno> <articleno>60.3</articleno> <articleno>60.4</articleno>  <articleno>70.1</articleno> <articleno>70.2</articleno> <articleno>70.3</articleno> <articleno>70.4</articleno> 

with following xslt doesn't work

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:template match="meta" name="tokenize">         <xsl:param name="separator" select="', '" />         <xsl:for-each select="tokenize(.,$separator)">                             <articleno><xsl:value-of select="../sku"/>.<xsl:value-of select="position()" /></articleno>         </xsl:for-each>     </xsl:template>   <xsl:template match="sku" />  </xsl:stylesheet> 

how can access sku correctly?

using xslt 2.0 output can achieved making small tweak in shared xsl. <sku> value can added variable , used format desired output.

<xsl:stylesheet version="2.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:template match="meta" name="tokenize">         <xsl:param name="separator" select="', '" />         <xsl:variable name="skuvalue" select="../sku" />         <xsl:for-each select="tokenize(.,$separator)">             <articleno>                 <xsl:value-of select="$skuvalue" />                 .                 <xsl:value-of select="position()" />             </articleno>         </xsl:for-each>     </xsl:template>     <xsl:template match="sku" /> </xsl:stylesheet> 

output

<articleno>60.1</articleno> <articleno>60.2</articleno> <articleno>60.3</articleno> <articleno>60.4</articleno> <articleno>70.1</articleno> <articleno>70.2</articleno> <articleno>70.3</articleno> <articleno>70.4</articleno> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -