A way to select a character at index point of tag??

Questions about XML that are not covered by the other forums should go here.
Posts: 1
Joined: Thu Dec 13, 2018 8:25 am

A way to select a character at index point of tag??

Post by voltaparabol » Thu Dec 13, 2018 8:40 am

Hello everyone, I am somewhat new to XML and just begun using it A LOT at work. I have this problem I want to resolve but I am not sure if I can do this in XML. Basically, I want to take the very first character of a tag from incoming XML <App_Data App="MOD" Name="Episode_Number" Value="303"/> and assign it to another tag that is empty. I am trying to get the first character of Episode_Number which is 3 and represents the season number. I then want to put that into the season number tag but I am not sure how to go about that. My transform rule would look something like:

<input Episode_Number="*" Provider_ID="epix.com">
<Season_Number>Episode_Number.char(0)</Season_Number> **Episode_Number.char(0) is JAVA syntax because I dont know how else to express it**

Any advice would help. Please excuse my rookie-ness if I am posting in the wrong area or if this doesnt even make sense. :shock:

Posts: 2696
Joined: Tue May 17, 2005 4:01 pm

Re: A way to select a character at index point of tag??

Post by adrian » Wed Dec 19, 2018 1:16 pm


Are you planning to do this by means of an XSLT transformation?

You seem to be calling everything a "tag", but some are attributes or attribute values. A tag usually refers to an element.
You have to learn a bit of the XML technology and its terminology before starting to use it. Without the terminology it is difficult to understand the means you plan to use and the desired result. I did get part of what is the desired result, but that is just a piece of the result that you are describing. Provide a broader input and output (desired result), not just a single entry.

This is the programmer's approach to XSLT (via xsl:for-each):

Code: Select all

        <xsl:template match="/">
<xsl:for-each select="//App_Data[@Name = 'Episode_Number']">
<input Episode_Number="{@Value}" Provider_ID="epix.com">
<xsl:value-of select="substring(@Value, 1, 1)"/>
This code assumes you have multiple "App_Data" elements and each useful one has the attribute Name = 'Episode_Number'. Assuming the output is still XML, you need a single root element. So, this code adds an "outroot" root element/tag for the output that surrounds all the "input" elements.
This outputs something like this:

Code: Select all

<input Episode_Number="303" Provider_ID="epix.com">
<input Episode_Number="405" Provider_ID="epix.com">
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Post Reply