XSLT file - create sections/line breaks/portions on a given variable
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Here's a way that you can a line between the elements you're looking for
Start by configuring your input tool to read as csv, with the following options
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.
This separates the groups while maintaining a valid xml file structure in [Field_1].
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Amazing, many thanks Dan!
