Вопрос

Is there any way to get this to sort in the order of the select statement when it finds one or more PIDs?

<xsl:apply-templates select="td:Benutzer_zu_POI[
td:PID = '400639' or 
td:PID = '400929' or
td:PID = '401184' or
td:PID = '401006' or
td:PID = '430003408' or
td:PID = '401519' or
td:PID = '400660' or
td:PID = '500287' or
td:PID = '200461' or
td:PID = '400756']">

Many thanks for any help!

Это было полезно?

Решение

You can, but it's not as automatic as you may be hoping. It would go something like this:

<xsl:apply-templates select="td:Benutzer_zu_POI[
td:PID = '400639' or 
td:PID = '400929' or
td:PID = '401184' or
td:PID = '401006' or
td:PID = '430003408' or
td:PID = '401519' or
td:PID = '400660' or
td:PID = '500287' or
td:PID = '200461' or
td:PID = '400756']">
   <xsl:sort select="string-length(
                       substring-before(
                         '|400639|400929|401184|401006|...|400756|',
                         concat('|', td:PID, '|')))"
             data-type="number" />
</xsl:apply-templates>

To explain how this works, the intent is to produce smaller numbers as a result of the select, depending on the item's order. So for example, for 400639, this evaluates to:

string-length(
   substring-before(
     '|400639|400929|401184|401006|...|400756|',
     '|400639|'))

string-length('')

0

for 401184, it's

string-length(
   substring-before(
     '|400639|400929|401184|401006|...|400756|',
     '|401184|'))

string-length('|400639|400929')

14

and so on.

The purpose of the concat() is to delimit the value in pipe symbols to prevent partial matches. If we didn't use the concat(), you might have a situation like this:

 (assume td:PID = 456)

 string-length(
   substring-before(
     '|123456|234567|34567|456|',
     '456'))

 string-length(
     '|123')

 4

meaning that 456 would be placed before 23456 and 34567 when it should actually be after them. When it's surrounded in delimiters, this doesn't happen:

 string-length(
   substring-before(
     '|123456|234567|34567|456|',
     '|456|'))

 string-length(
     '|123456|234567|34567')

 20

Другие советы

Would this do the trick?

<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '400639']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '401184']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '401006']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '430003408']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '401519']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '400660']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '500287']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '200461']/>
<xsl:apply-templates select="td:Benutzer_zu_POI[td:PID = '400756']/>

(Whether it's equivalent or not depends on the details of your data, which you haven't shown us. Your version will only display each Benutzer once even if it matches several of the PIDs.).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top