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 8744921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:55:16+00:00 2026-06-13T11:55:16+00:00

I’ve got a problem with some XSLT transformations. In my XML data there are

  • 0

I’ve got a problem with some XSLT transformations.
In my XML data there are some Coordinate Elements like this:

XML:

[...]
<polygon some="attributes">
  <coordinates>
    <point>(8.234/9.435)</point>
    <point>(2.456/5.678)</point>
    [...]
  </coordinates>
</polygon>
[...]

And so on.
The value of represents an x and a y coordinate (x/y).
Now I have to get from specific coordinate sets the biggest or the smallest value of x OR y.

We are using msxml in our c++ code so I can’t use XSLT 2.0 or XPath 2.0 for min() and max() functions.

The format (x/y) is static and I cant change it as well, because it’s an output of a program.

I tried to do it in XSLT like this:

XSLT:

<xsl:template name="getMinOf"> <!--this one is getting nodeset, min/max, x/y params-->
  <xsl:for-each select="$nodeSet"> <!--in this case "//polygon/coordinates/point"-->
    *<xsl:choose>
      <xsl:when test="$MinOrMax = 'min' ">
        <xsl:choose>
          <xsl:when test="$XorY = 'x'">*
        <xsl:sort select="substring-before(substring-after(.,'('),'/')" data-type="number" order="ascending"/> <!--Here is my problem-->
              <xsl:if test="position() = 1">
                <xsl:value-of select="." /><!--  return xMin -->
              </xsl:if>
          </xsl:when>
      [...]
</xsl:template>

The select=”substring-before(substring-after(.,'(‘),’/’)” should get the part between ( and /, the x coordinate.
If i do a

<!--this one does return the x value.-->
<xsl:value-of select="substring-before(substring-after(.,'('),'/')"/>

So… I hope you can understand my problem and can help me. I don’t know how to get further.
Thanks.

Edit:
Forgot the desired output. It should be something like this:

<polygon>
  <xMin>2.456</xMin>
  <xMax>8.234</xMax>
  <yMin>5.678</yMin>
  <yMax>9.435</yMax>
</polygon>
  • 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-06-13T11:55:17+00:00Added an answer on June 13, 2026 at 11:55 am

    Although not mentioned in the question, I am guessing your issue is that your are getting the message “Keyword xsl:sort may not be used here.”, which occurs because your xsl:sort is nested within an xsl:when when it should be directly under the xsl:for-each

    Effectively you are trying to do conditional sorting, based on your parameter. One condition is whether to sort on either the x or y co-ordinate, and the other whether to sort ascending or descending.

    For the ordering, you can define a variable, which will holding either ‘ascending’ or ‘descending’, and then order by that:

      <xsl:variable name="order">
         <xsl:choose>
            <xsl:when test="$MinOrMax='max'">descending</xsl:when>
            <xsl:otherwise>ascending</xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:for-each select="coordinates/point">
         <xsl:sort select="substring-before(substring-after(.,'('),'/')" data-type="number" order="{$order}"/>
    

    The next issue is how to do select either the ‘x’ or ‘y’ co-ordinate based on your parameter. One way could be to have a xsl:choose to choose between the sorting methods

      <xsl:choose>
         <xsl:when test="$XorY='x'">
            <xsl:for-each select="coordinates/point">
               <xsl:sort select="substring-before(substring-after(.,'('),'/')" data-type="number" order="{$order}"/>
               <xsl:if test="position() = 1">
                  <xsl:value-of select="substring-before(substring-after(.,'('),'/')"/>
               </xsl:if>
            </xsl:for-each>         
         </xsl:when>
         <xsl:otherwise>
            <xsl:for-each select="coordinates/point">
               <xsl:sort select="substring-before(substring-after(.,'/'),')')" data-type="number" order="{$order}"/>
               <xsl:if test="position() = 1">
                  <xsl:value-of select="substring-before(substring-after(.,'/'),')')"/>
               </xsl:if>
            </xsl:for-each>         
         </xsl:otherwise>
      </xsl:choose>
    

    However, there is a way to avoid this potential code duplication, and have a single xsl:for-each. Try this for the sort

         <xsl:sort select="concat(
              substring(substring-before(substring-after(.,'('),'/'), 1, 100 * ($XorY = 'x')), 
              substring(substring-before(substring-after(.,'/'),')'), 1, 100 * ($XorY = 'y')))" 
           data-type="number" order="{$order}"/>
    

    This takes advantage of the fact that ($XorY = 'x') will evaluate to either 0 or 1 in the expression. To understand it more, it is effectively doing a concatenation of these two expressions:

    substring(<x co-ordinate>, 1, 100 * <0 or 1>)
    substring(<y co-ordinate>, 1, 100 * <0 or 1>)
    

    When $XorY = ‘x’ then 1 is returned, so the first substring (the x co-ordinate) returns a full string, but the second substring returns an empty string. When $XorY = ‘y’ the opposite is true and the second substring (the y co-ordinate) is returned.

    Try this XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="polygon">
          <polygon>
             <xMin>
                <xsl:call-template name="getMinOf">
                   <xsl:with-param name="MinOrMax" select="'min'" />
                   <xsl:with-param name="XorY" select="'x'" />
                </xsl:call-template>   
             </xMin>
             <xMax>
                <xsl:call-template name="getMinOf">
                   <xsl:with-param name="MinOrMax" select="'max'" />
                   <xsl:with-param name="XorY" select="'x'" />
                </xsl:call-template>   
             </xMax>
             <yMin>
                <xsl:call-template name="getMinOf">
                   <xsl:with-param name="MinOrMax" select="'min'" />
                   <xsl:with-param name="XorY" select="'y'" />
                </xsl:call-template>   
             </yMin>         
             <yMax>
                <xsl:call-template name="getMinOf">
                   <xsl:with-param name="MinOrMax" select="'max'" />
                   <xsl:with-param name="XorY" select="'y'" />
                </xsl:call-template>   
             </yMax>
          </polygon>
       </xsl:template>
    
       <xsl:template name="getMinOf">
          <xsl:param name="MinOrMax"/>
          <xsl:param name="XorY"/>
          <xsl:variable name="order">
             <xsl:choose>
                <xsl:when test="$MinOrMax='max'">descending</xsl:when>
                <xsl:otherwise>ascending</xsl:otherwise>
             </xsl:choose>
          </xsl:variable>
          <xsl:for-each select="coordinates/point">
             <xsl:sort select="concat(substring(substring-before(substring-after(.,'('),'/'), 1, 100 * ($XorY = 'x')), substring(substring-before(substring-after(.,'/'),')'), 1, 100 * ($XorY = 'y')))" data-type="number" order="{$order}"/>
             <xsl:if test="position() = 1">
                <xsl:value-of select="concat(substring(substring-before(substring-after(.,'('),'/'), 1, 100 * ($XorY = 'x')), substring(substring-before(substring-after(.,'/'),')'), 1, 100 * ($XorY = 'y')))"/>
             </xsl:if>
          </xsl:for-each>
       </xsl:template>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <polygon>
       <xMin>2.456</xMin>
       <xMax>8.234</xMax>
       <yMin>5.678</yMin>
       <yMax>9.435</yMax>
    </polygon>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.