Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

XSLT file - create sections/line breaks/portions on a given variable

HenpetsGordres1
8 - Asteroid

Hello,

 

I am attempting to parse an XSLT file, and need to split it up to compare on a given variable. How can I do this? Example below:

 

If the XSLT file appeared like this:

 

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:variable name="Names">
<xsl:choose>
<xsl:when test="John">
<xsl:value-of select="10"/>
</xsl:when>
<xsl:when test="Jack">
<xsl:value-of select="12"/>
</xsl:when>
<xsl:when test="James">
<xsl:value-of select="14"/>
</xsl:when>
<xsl:when test="Jim">
<xsl:value-of select="16"/>
</xsl:when>
<xsl:when test="Joe">
<xsl:value-of select="18"/>
</xsl:when>
<xsl:when test="Juan">
<xsl:value-of select="19"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="21"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="John">
<xsl:value-of select="44"/>
</xsl:when>
<xsl:when test="Jack">
<xsl:value-of select="36"/>
</xsl:when>
<xsl:when test="James">
<xsl:value-of select="98"/>
</xsl:when>
<xsl:when test="Jim">
<xsl:value-of select="54"/>
</xsl:when>
<xsl:when test="Joe">
<xsl:value-of select="142"/>
</xsl:when>
<xsl:when test="Juan">
<xsl:value-of select="10"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="65"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

 

 

Could I specify "</xsl:choose>" as the variable I want to break up and portion my file by? So the output, in Alteryx, would appear something like the following:

 

</xsl:choose>
<xsl:choose>
<xsl:when test="John">
<xsl:value-of select="10"/>
</xsl:when>
<xsl:when test="Jack">
<xsl:value-of select="12"/>
</xsl:when>
<xsl:when test="James">
<xsl:value-of select="14"/>
</xsl:when>
<xsl:when test="Jim">
<xsl:value-of select="16"/>
</xsl:when>
<xsl:when test="Joe">
<xsl:value-of select="18"/>
</xsl:when>
<xsl:when test="Juan">
<xsl:value-of select="19"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="21"/>
</xsl:otherwise>
</xsl:choose>
</xsl:choose>
<xsl:choose>
<xsl:when test="John">
<xsl:value-of select="44"/>
</xsl:when>
<xsl:when test="Jack">
<xsl:value-of select="36"/>
</xsl:when>
<xsl:when test="James">
<xsl:value-of select="98"/>
</xsl:when>
<xsl:when test="Jim">
<xsl:value-of select="54"/>
</xsl:when>
<xsl:when test="Joe">
<xsl:value-of select="142"/>
</xsl:when>
<xsl:when test="Juan">
<xsl:value-of select="10"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="65"/>
</xsl:otherwise>
</xsl:choose>

 

 

 

 

I'm unsure whether to read the file in as a CSV or XML initially, any help would be greatly appreciated!

 

Many thanks.

 

PLEASE NOTE: I COULD NOT UPLOAD THE XSLT FILE AS IS NOT ACCEPTED. APOLOGIES.

 

2 REPLIES 2
danilang
19 - Altair
19 - Altair

Hi @HenpetsGordres1 

 

Here's a way that you can a line between the elements you're looking for

 

w.png

 

Start by configuring your input tool to read as csv, with the following options

 

i.png

 

Add a recordID and change its type to Double.  Append the element that you're looking for, and then filter for both the open and close tags for this open.  Double all these rows, clear the tag from every second one. Add .5 to the RecordID if it's an open tag, subtract .5 if it's a close and do nothing if it's empty.  Union all the rows together and sort on recordID.

 

r.png

 

This separates the groups while maintaining a valid xml file structure in [Field_1].   

 

Dan 

HenpetsGordres1
8 - Asteroid

Amazing, many thanks Dan!

Labels