Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:54:38+00:00 2026-05-31T06:54:38+00:00

I have a input XML like this : <in_xml> <company> <project> ProjNo1 ProjNo2 ProjNo3

  • 0

I have a input XML like this :

<in_xml>
 <company>
  <project>
    ProjNo1
    ProjNo2
    ProjNo3
  </project>
 </company>
</in_xml>

A simple XSLT is applied to this source, which writes another XML with the value of Project Tag.
The Project tag in input xml has three lines , it could be one or more line(s). I am looking at way for the XSLT to read only the first line, in case there are more than one and write the first line in the output xml.
The current XSLT is very simple as it just reads the Project tag and spits out the value, hence the code is not attached.

Regards.

I have added the answer to the question, see below @Maestro’s answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:54:40+00:00Added an answer on May 31, 2026 at 6:54 am

    If you are in the happy circumstances of being able to apply XSLT 2.0, the following may help:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:template match="//project/text()">
            <xsl:value-of select="tokenize(normalize-space(.),' ')[1]" />
        </xsl:template>
    </xsl:stylesheet>
    

    Explanation: first normalize-space() to replace all whitespace strings by a single blank (and cut off leading and trailing whitespace), then split into words, then take the first one.

    In XSLT 1.0 you could use

    <xsl:value-of select="substring-before(normalize-space(.), ' ')"/>
    

    instead. Less flexible if the second word has to be selected, but for the first word it works OK.

    EDIT

    you asked how to retrieve a first line in XSLT 1.0 – problem here is the leading whitespace which may contain a LF so you cannot just substring-before the first LF.
    The below can probably be improved upon, but it works fine:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:template match="//project/text()">
            <xsl:variable name="afterLeadingWS"
    select="substring-after(., substring-before(.,substring-before(normalize-space(.), ' ')))"/>
            <xsl:choose>
                <xsl:when test="contains($afterLeadingWS, '&#xA;')">
                     <xsl:value-of select="substring-before($afterLeadingWS, '&#xA;')"/>
                </xsl:when>
                <xsl:otherwise>
                     <xsl:value-of select="$afterLeadingWS"/>
                </xsl:otherwise>
            </xsl:choose>
       </xsl:template>
    </xsl:stylesheet>
    

    Explanation: first get first word as before, then determine the whitespace before that first word, then get everything after that leading whitespace, then get the first line, which is the string before a LF character. It may just happen that there is no LF except maybe in the leading whitespace, hence the choose function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this use case of an xml file with input like Input: <abc
I have an input XML document something like this: <text> <p> Download the software
I have a stored proc that takes an input of xml value like this:
I have a question. My input XML looks like <?xml version=1.0 encoding=UTF-8?> <Text> <Message>this
I have a chained XSLT 2.0 transformation scenario (using saxon), like this: - I1.xml
I have a style sheet like this <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:param
Lets say I have an xml structure like this: <s> <a> <b id=myid>value1</b> <c
I have an XML below like this and I want to add in another
in input XML I have a tag <name>Sample '</name> in XSL I transform this
I have rather large input XML files that must be converted to a given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.