| |

VerySource

 Forgot password?
 Register
Search
View: 1556|Reply: 9

How does xsl condition judgment go wrong?

[Copy link]

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Hong Kong

Post time: 2020-2-21 16:30:01
| Show all posts |Read mode
The xml node Prod_Code / Year has the text 2015 and 2016. The xml file is as follows:
....
         <Prod_Code> 000-000-001
<Year> 2015
...
               </ Year>
<Year> 2016
. . .
                </ Year>
</ Prod_Code>
....
. I use the following conditions in the xsl file to determine whether it is 2015 or 2016:
<xsl: for-each select = "./Prod_Code/Year">
Ranch
<xsl: if test = ". [text () = '2015'">
. . . .
</ xsl: if>
<xsl: if test = ". [text () = '2016']">
                             . . .
                           </ xsl: if>

In xmlns: xsl = "http://www.w3.org/TR/WD-xsl" this is OK, but in xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" What's wrong? What should I write in xmlns: xsl = "http://www.w3.org/1999/XSL/Transform"? Or how to implement such a function?
Also ask if you can assign node values ​​to style values ​​in xsl? That is to achieve the following functions:
<input type = "text" id = "<xsl: value-of select = '. // year [1]'>"> The syntax is wrong, I just want to achieve such a function. Can you do it
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-4 22:30:01
| Show all posts
<xsl: if test = "text () = '2015'">
. . . .
</ xsl: if>


<input type = "text" id = "{.// year [1]}">
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-6 22:30:02
| Show all posts
The answer upstairs is correct. . .
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 United States

Post time: 2020-5-10 10:00:01
| Show all posts
Passing by, the second floor should be OK
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Hong Kong

 Author| Post time: 2020-5-21 15:00:01
| Show all posts
<xsl: if test = "text () = '2015'">
. . . .
</ xsl: if>
No, report the following error
Required attribute 'select' is missing.
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Hong Kong

 Author| Post time: 2020-5-22 09:15:01
| Show all posts
Let me show you the xsl again:
<? xml version = "1.0" encoding = "gb2312"?>
<xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">
<xsl: template match = "/">
....

<xsl: for-each select = "./Prod_Code/Year">
The
<xsl: if test = "text () = '2015'">
<tr bgcolor = "silver">
<xsl: for-each select = "./ Y_M / Qty">
<td width = "80px" align = "left" valign

= "top" style = "font-size: 9pt;">
<xsl: value-of />
</ td>
</ xsl: for-each>
</ tr>
The
</ xsl: if>
<xsl: if test = "text () = '2016'">
<tr>
<xsl: for-each select = "./ Y_M / Qty">
<td width = "80px" align = "left" valign

= "top">
<input type = "text" id = "M01" size = "10"

value = "" font-size = "9pt" />
</ td>
</ xsl: for-each>
</ tr>
</ xsl: if>
</ xsl: for-each>

...
</ xsl: template>
</ xsl: stylesheet>
The xml part of the code to be formatted is as follows:
<? xml version = "1.0" encoding = "gb2312" standalone = "no"?>
<InputTable>
<Prod_CDesc> Product 1
<Prod_Code> 000-000-001
<Year> 2015
<Y_M> 2015-01
<Qty> 10.00 </ Qty>
</ Y_M>
                           ........
</ Year>
<Year> 2016
<Y_M> 2016-01
<Qty />
</ Y_M>
                    ................
</ Year>
</ Prod_Code>
</ Prod_CDesc>
...
</ InputTable>
Please help me look at it again, where is the problem?
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Hong Kong

 Author| Post time: 2020-5-22 14:30:02
| Show all posts
Please note that my namespace uses http://www.w3.org/1999/XSL/Transform instead of http://www.w3.org/TR/WD-xsl
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-5-23 19:00:01
| Show all posts
1. Your xml design is very unreasonable
2. There is a space after 2015, you can use substring (text (), 1,4) = '2015' to judge
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-6-1 17:30:01
| Show all posts
Boss, the problem is not here. My xml was generated by the program. When I posted more lines, I still reported the following error:
Required attribute 'select' is missing.
It is possible in http://www.w3.org/TR/WD-xsl, but not in http://www.w3.org/1999/XSL/Transform, I will use it in vs 2015 now, It seems that only http://www.w3.org/1999/XSL/Transform namespace can be used.
So there is no way.
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Hong Kong

 Author| Post time: 2020-7-7 09:00:01
| Show all posts
This problem has been solved. There is a new question I want to ask everyone, how to use xsl to format xml into asp.net file, that is, aspx file, the most important thing is to format the object to the format starting with <asp:. Can't just add runat="server"
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list