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 »
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**
</input>
Any advice would help. Please excuse my rookie-ness if I am posting in the wrong area or if this doesnt even make sense.
<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**
</input>
Any advice would help. Please excuse my rookie-ness if I am posting in the wrong area or if this doesnt even make sense.

-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: A way to select a character at index point of tag??
Hi,
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): 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:
Regards,
Adrian
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="/">
<outroot>
<xsl:for-each select="//App_Data[@Name = 'Episode_Number']">
<input Episode_Number="{@Value}" Provider_ID="epix.com">
<Season_Number>
<xsl:value-of select="substring(@Value, 1, 1)"/>
</Season_Number>
</input>
</xsl:for-each>
</outroot>
</xsl:template>
This outputs something like this:
Code: Select all
<outroot>
<input Episode_Number="303" Provider_ID="epix.com">
<Season_Number>3</Season_Number>
</input>
<input Episode_Number="405" Provider_ID="epix.com">
<Season_Number>4</Season_Number>
</input>
...
</outroot>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service