33482

How I can parse Pipeline sign from string in xslt

Question:

How I can parse pipeline sign from fields in xslt. e.g.

dummy1|dummy2|dummy3|dummy4

Regards, Sarah

Answer1:

If you use an XSLT 2.0 processor you can use the tokenize function (<a href="http://www.w3.org/TR/xpath-functions/#func-tokenize" rel="nofollow">http://www.w3.org/TR/xpath-functions/#func-tokenize</a>) e.g. with an input of

<foo>dummy1|dummy2|dummy3|dummy4</foo>

you can match

<xsl:template match="foo"> <xsl:value-of select="tokenize(., '\|')"/> </xsl:template>

to output dummy1 dummy2 dummy3 dummy4. If you use an XSLT 1.0 processor you can check whether it supports an extension function like <a href="http://www.exslt.org/str/functions/tokenize/" rel="nofollow">http://www.exslt.org/str/functions/tokenize/</a> or you need to write a recursive, named template splitting up the input.

Answer2:

In xlst 1.0 I usually use recursive call of named template, e.g.

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:variable name="dummyVar" select="'dummy1|dummy2|dummy3|dummy4'" /> <xsl:variable name="delimiter" select="'|'" /> <xsl:template match="/"> <dummies> <xsl:call-template name="parseDummy"> <xsl:with-param name="parsedString" select="$dummyVar" /> </xsl:call-template> </dummies> </xsl:template> <xsl:template name="parseDummy"> <xsl:param name="parsedString" /> <xsl:choose> <xsl:when test="contains($parsedString, $delimiter)"> <xsl:element name="{substring-before($parsedString, $delimiter)}" /> <xsl:call-template name="parseDummy"> <xsl:with-param name="parsedString" select="substring-after($parsedString, $delimiter)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:element name="{$parsedString}" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>

It's on you what you need to do with parsed values, in example I construct elements with names of dummies.

Be careful about context which is changing.

Recommend

  • How do I retrieve the text in a table column using Selenium RC?
  • Failing to get duration of youtube video using xpath
  • Searching an XML file using PHP [closed]
  • parsing xml and html page with lxml and requests package in python
  • Custom Nav Title offset ios 11
  • garbled css name when styling within UiBinder
  • How to open html table in xls on click of a button
  • How to retrieve information from antrun back to maven?
  • Django model inheritance, filtering models
  • Jquery popup on mouse over of calendar control
  • Check for zero lines output from command over SSH
  • Functions in global context
  • How to clear text inside text field when radio button is select
  • Meteor helpers not available in Angular template
  • Read a local file using javascript
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Update CALayer sublayers immediately
  • Splitting given String into two variables - php
  • output of program is not same as passed argument
  • Check if a string to interpolate provides expected placeholders
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Statically linking a C++ library to a C# process using CLI or any other way
  • what is the difference between the asp.net mvc application and asp.net web application
  • Build own AppleScript numerical error handling
  • Why winpcap requires both .lib and .dll to run?
  • Unanticipated behavior
  • Matrix multiplication with MKL
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal