XSLT: tips and tricks: how to process node1, node2, …, nodeN

Very often people don’t understand how to process structures like

<forecast>
      <qty1>1</qty1>
      <date1>01022014</date1>

      <qty2>1</qty2>
      <date2>01022014</date2><qtyN>1</qtyN>
      <dateN>01022014</dateN>
</forecast>

They create N templates or repeat the same code again and again, changing the names: qty1/date1, qty2/date2, … But all they need to do is to use the name() function, like this:

<xsl:for-each select="forecast/*[ starts-with(name(), 'qty') ]">

I think the idea is self explanatory…

Gennady Kim

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s