在工作中大量使用XSLT进行各种文档的转换。但其调试过程还是比较麻烦的。这里分享一个很好用的命令行工具,可以进行XSLT的调试。以下环境是针对Ubuntu 18.04 LTS的。 ![image.png](https://images.hive.blog/DQmS8hWyQyHnAZwZPvMmm3VqnddLsxUucCcAQREkJw5wqU4/image.png) 安装 sudo apt-get install xalan 检查xalan的版本号: xalan -v 下面来做一个简单的测试。首先创建一个简单的XML文件text.xml: <?xml version="1.0" encoding="UTF-8"?> <students> <student> <id>91001</id> <name>Jim</name> </student> <student> <id>91002</id> <name>Julie</name> </student> <student> <id>91003</id> <name>Stuart</name> </student> </students> 创建测试的XSLT文件:test.xsl: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>Students</h2> <table border="1"> <tr bgcolor="#9acd32"> <th style="text-align:left">ID</th> <th style="text-align:left">Name</th> </tr> <xsl:for-each select="students/student"> <tr> <td><xsl:value-of select="id"/></td> <td><xsl:value-of select="name"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> 在命令行运行: xalan -in test.xml -xsl test.xsl -out out.html 可以看到生成的HTML文件: <html> <body> <h2>Students</h2> <table border="1"> <tr bgcolor="#9acd32"> <th style="text-align:left">ID</th><th style="text-align:left">Name</th> </tr> <tr> <td>91001</td><td>Jim</td> </tr> <tr> <td>91002</td><td>Julie</td> </tr> <tr> <td>91003</td><td>Stuart</td> </tr> </table> </body> </html> 其实xalan命令行工具还有很多好用的选项。比如运行如下参数: xalan -in test.xml -xsl test.xsl -out out.html -tg 这样就能看到解析过程中每一个具体步骤: ![image.png](https://images.hive.blog/DQmcJCBLjw7As8kEVdSmW9roNhkkP5d1bMvcngHxp7EXPUk/image.png) 如果想要查看在解析过程中被调用的每一个模板,使用参数tt: xslt xalan -in test.xml -xsl test.xsl -out out.html -tt 如果想要监测在解析过程中对每一个XML元素的选取: xalan -in test.xml -xsl test.xsl -out out.html -ts 其输出类似于: ![image.png](https://images.hive.blog/DQmSwxss6sKPEBtboZQQwogC54U2LhE4BoPJWtPggNCdxRp/image.png)
author | aafeng |
---|---|
permlink | xslt |
category | hive-105017 |
json_metadata | {"tags":["cn","cn-curation","cn-reader","cn-programming"],"image":["https://images.hive.blog/DQmS8hWyQyHnAZwZPvMmm3VqnddLsxUucCcAQREkJw5wqU4/image.png","https://images.hive.blog/DQmcJCBLjw7As8kEVdSmW9roNhkkP5d1bMvcngHxp7EXPUk/image.png","https://images.hive.blog/DQmSwxss6sKPEBtboZQQwogC54U2LhE4BoPJWtPggNCdxRp/image.png"],"app":"hiveblog/0.1","format":"markdown"} |
created | 2020-09-16 15:18:21 |
last_update | 2020-09-16 15:18:21 |
depth | 0 |
children | 0 |
last_payout | 2020-09-23 15:18:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 6.316 HBD |
curator_payout_value | 5.646 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,224 |
author_reputation | 546,202,457,352,023 |
root_title | 如何在命令行测试XSLT |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 99,659,977 |
net_rshares | 43,568,548,675,778 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
abit | 0 | 13,125,312,989,472 | 50% | ||
wongshiying | 0 | 4,058,431,595 | 47.19% | ||
gerber | 0 | 188,538,156,011 | 3% | ||
ezzy | 0 | 212,164,840,698 | 3% | ||
livingfree | 0 | 188,002,409,470 | 2% | ||
exyle | 0 | 185,976,674,773 | 3% | ||
tensaix2j | 0 | 17,946,483,509 | 47.19% | ||
laoyao | 0 | 27,919,080,988 | 60% | ||
somebody | 0 | 27,914,520 | 60% | ||
midnightoil | 0 | 98,028,761,097 | 60% | ||
xiaohui | 0 | 554,771,492,244 | 60% | ||
oflyhigh | 0 | 2,974,995,308,084 | 60% | ||
yulan | 0 | 9,608,760,500 | 60% | ||
bert0 | 0 | 2,065,448,438 | 0.4% | ||
helene | 0 | 729,799,280,891 | 60% | ||
sweetsssj | 0 | 13,840,493,512,415 | 33% | ||
netaterra | 0 | 58,028,853,524 | 2.7% | ||
someguy123 | 0 | 97,870,345,484 | 3% | ||
cnfund | 0 | 36,807,748,467 | 47.19% | ||
justyy | 0 | 394,005,011,624 | 47.19% | ||
btshuang | 0 | 633,866,533 | 47.19% | ||
created | 0 | 447,985,357,185 | 2% | ||
devilwsy | 0 | 1,681,650,910 | 47.19% | ||
janiceting | 0 | 1,682,011,724 | 47.19% | ||
blackbunny | 0 | 43,831,328,707 | 60% | ||
elizacheng | 0 | 17,324,414,402 | 9% | ||
lingfei | 0 | 47,481,128,112 | 60% | ||
dune69 | 0 | 20,583,870,446 | 3% | ||
aleister | 0 | 7,513,786,700 | 10% | ||
mys | 0 | 169,285,653 | 0.3% | ||
guyverckw | 0 | 96,857,791,027 | 47.19% | ||
nuagnorab | 0 | 208,554,628,326 | 47.19% | ||
rycharde | 0 | 1,198,561,255 | 10% | ||
linuslee0216 | 0 | 583,910,785 | 47.19% | ||
wilkinshui | 0 | 70,928,760,347 | 47.19% | ||
exec | 0 | 148,362,282,517 | 60% | ||
eval | 0 | 472,605,984 | 60% | ||
alphacore | 0 | 31,092,011,181 | 1.81% | ||
aaronli | 0 | 71,427,048,546 | 47.19% | ||
marylaw | 0 | 9,902,071,886 | 47.19% | ||
shenchensucc | 0 | 26,836,312,784 | 47.19% | ||
krischy | 0 | 9,859,353,857 | 37.75% | ||
biuiam | 0 | 1,086,023,840 | 47.19% | ||
susanli3769 | 0 | 356,088,270,644 | 100% | ||
davidmendel | 0 | 4,884,420,461 | 37.75% | ||
mrpointp | 0 | 47,831,818,508 | 47.19% | ||
mygod | 0 | 633,706,294 | 47.19% | ||
shitsignals | 0 | 1,245,040,082 | 3% | ||
everrich | 0 | 4,849,147,886 | 47.19% | ||
syh7758520 | 0 | 12,652,711,439 | 47.19% | ||
nicolemoker | 0 | 12,984,339,003 | 37.75% | ||
aafeng | 0 | 424,723,023,328 | 100% | ||
karja | 0 | 108,339,439,066 | 5% | ||
mrspointm | 0 | 51,953,203,702 | 47.19% | ||
liumei | 0 | 6,135,508,192 | 47.19% | ||
kimzwarch | 0 | 9,169,483,161 | 4% | ||
redouanemez | 0 | 187,734,063,462 | 100% | ||
waiyee422 | 0 | 4,215,288,284 | 47.19% | ||
accelerator | 0 | 44,235,430,934 | 5% | ||
tomiscurious | 0 | 10,143,901,138 | 3.23% | ||
rosatravels | 0 | 309,603,298,799 | 47.19% | ||
xiaoshancun | 0 | 7,050,807,213 | 47.19% | ||
minloulou | 0 | 9,777,715,295 | 47.19% | ||
victory622 | 0 | 215,145,781,891 | 100% | ||
miti | 0 | 2,886,632,464 | 15% | ||
jychbetter | 0 | 26,561,903,066 | 47.19% | ||
winniex | 0 | 153,244,610,998 | 47.19% | ||
caladan | 0 | 6,604,850,303 | 2.85% | ||
jianan | 0 | 1,551,821,107 | 47.19% | ||
emrebeyler | 0 | 62,508,818,326 | 3% | ||
windowglass | 0 | 2,027,350,748 | 47.19% | ||
zmx | 0 | 6,049,783,898 | 47.19% | ||
nileelily | 0 | 2,870,269,272 | 47.19% | ||
jacktan | 0 | 1,369,040,622 | 23.59% | ||
angelina6688 | 0 | 2,169,302,570 | 47.19% | ||
lebin | 0 | 87,878,300,095 | 50% | ||
itchyfeetdonica | 0 | 64,724,199,379 | 30% | ||
cheva | 0 | 16,091,066,901 | 47.19% | ||
nealmcspadden | 0 | 40,323,225,572 | 3% | ||
maiyude | 0 | 1,534,284,166 | 47.19% | ||
piotrgrafik | 0 | 159,563,028,250 | 40% | ||
purefood | 0 | 18,992,816,859 | 3% | ||
wilhb81 | 0 | 197,666,176,629 | 47.19% | ||
emmali | 0 | 33,105,590,694 | 47.19% | ||
youandme | 0 | 940,874,428 | 100% | ||
kirato | 0 | 81,997,445,668 | 47.19% | ||
nostalgic1212 | 0 | 57,830,792,033 | 47.19% | ||
pkocjan | 0 | 1,360,603,093 | 2.4% | ||
shentrading | 0 | 13,783,646,947 | 47.19% | ||
also.einstein | 0 | 3,837,992,788 | 47.19% | ||
fishbb | 0 | 920,481,383 | 23.59% | ||
ericet | 0 | 2,273,128,546 | 47.19% | ||
josevas217 | 0 | 732,639,758 | 0.32% | ||
bestboom | 0 | 13,628,478,194 | 3% | ||
aellly | 0 | 23,492,154,243 | 47.19% | ||
huangzuomin | 0 | 83,745,624,670 | 47.19% | ||
liewsc | 0 | 1,379,558,617 | 23.59% | ||
tanzy | 0 | 633,378,507 | 23.59% | ||
freddio | 0 | 11,859,107,945 | 15% | ||
themightyvolcano | 0 | 2,747,078,845 | 3% | ||
fishdd | 0 | 897,315,519 | 23.59% | ||
payroll | 0 | 82,871,700,757 | 2% | ||
andrewma | 0 | 10,754,088,173 | 47.19% | ||
softmetal | 0 | 7,491,553,446 | 47.19% | ||
xiaoliang | 0 | 7,126,106,996 | 47.19% | ||
i-d | 0 | 254,864,619,100 | 47.19% | ||
steem.services | 0 | 21,539,805,992 | 0.75% | ||
honoru | 0 | 56,658,045,689 | 47.19% | ||
hmayak | 0 | 11,472,769,702 | 47.19% | ||
archisteem | 0 | 1,623,749,155 | 7.5% | ||
springfall | 0 | 3,484,536,535 | 100% | ||
fishlucy | 0 | 14,489,520,872 | 50% | ||
hkphotography | 0 | 1,435,667,458 | 47.19% | ||
ronbong | 0 | 1,549,581,171 | 47.19% | ||
hsidik | 0 | 5,395,590,916 | 100% | ||
robertyan | 0 | 7,560,587,663 | 47.19% | ||
xiaoyuanwmm | 0 | 793,057,684 | 47.19% | ||
kidsreturn | 0 | 2,491,817,501 | 47.19% | ||
tydebbie | 0 | 3,662,952,487 | 23.59% | ||
moneybaby | 0 | 16,398,402,862 | 47.19% | ||
suonghuynh | 0 | 8,759,285,214 | 6% | ||
ybeyond | 0 | 2,512,778,306 | 47.19% | ||
team-cn | 0 | 117,481,263,424 | 47.19% | ||
hardmetal | 0 | 2,880,417,060 | 100% | ||
coder-bts | 0 | 9,271,610,356 | 100% | ||
chick-fil-a | 0 | 1,594,492,860 | 47.19% | ||
redlobster | 0 | 1,598,986,356 | 47.19% | ||
fiveguys | 0 | 801,537,166 | 47.19% | ||
marcoy2j | 0 | 1,385,286,502 | 47.19% | ||
tiffany4ever | 0 | 16,466,088,114 | 47.19% | ||
bonefish | 0 | 1,519,339,550 | 47.19% | ||
chilis | 0 | 1,591,158,419 | 47.19% | ||
olive-garden | 0 | 783,789,024 | 47.19% | ||
zhuanzhibufu | 0 | 2,888,079,866 | 100% | ||
shine.wong | 0 | 1,721,025,042 | 47.19% | ||
shuxuan | 0 | 1,549,171,981 | 47.19% | ||
teamvn | 0 | 29,860,139,120 | 43.93% | ||
dalz | 0 | 4,443,311,693 | 1.5% | ||
sunai | 0 | 1,119,844,617 | 100% | ||
zongli | 0 | 2,112,029,273 | 100% | ||
zhuxi | 0 | 2,866,616,479 | 100% | ||
julian2013 | 0 | 63,601,597,124 | 47.19% | ||
dlike | 0 | 35,691,123,166 | 3% | ||
melaniewang | 0 | 7,755,631,341 | 47.19% | ||
teamcn-news | 0 | 783,261,051 | 47.19% | ||
wenxuecity | 0 | 925,935,690 | 47.19% | ||
mitbbs | 0 | 1,525,830,446 | 47.19% | ||
artsymelanie | 0 | 25,610,934,780 | 47.19% | ||
engrave | 0 | 39,641,541,029 | 2.4% | ||
bobby.madagascar | 0 | 1,134,840,048 | 1.5% | ||
slientstorm | 0 | 26,310,394,681 | 47.19% | ||
laissez-faire | 0 | 30,702,207 | 100% | ||
pet.society | 0 | 2,022,434,842,925 | 47.19% | ||
annepink | 0 | 90,154,583,122 | 47.19% | ||
cherryzz | 0 | 152,770,543,538 | 47.19% | ||
berthold | 0 | 2,268,631,888 | 6% | ||
teamcn-shop | 0 | 11,329,577,014 | 47.19% | ||
yanyanbebe | 0 | 1,659,947,992 | 47.19% | ||
followjohngalt | 0 | 21,378,160,826 | 3% | ||
kelvinzhang | 0 | 2,541,697,599 | 47.19% | ||
wherein | 0 | 161,471,197,541 | 36% | ||
zerofive | 0 | 887,626,533 | 47.19% | ||
ahua | 0 | 529,386,307 | 47.19% | ||
morningshine | 0 | 57,910,288,466 | 47.19% | ||
cnstm | 0 | 100,751,725,889 | 36% | ||
permaculturedude | 0 | 1,150,940,411 | 3% | ||
cn-activity | 0 | 1,453,472,568 | 47.19% | ||
davidchen | 0 | 32,978,421,437 | 47.19% | ||
cecilian | 0 | 3,581,393,001 | 47.19% | ||
devyleona | 0 | 19,389,388,806 | 47.19% | ||
yanhan | 0 | 26,308,481,553 | 47.19% | ||
foodiecouple | 0 | 614,737,436 | 47.19% | ||
m18207319997 | 0 | 579,246,536 | 47.19% | ||
lovelemon | 0 | 1,046,540,802 | 47.19% | ||
theinspiration | 0 | 573,677,202 | 100% | ||
epic4chris | 0 | 584,044,082 | 100% | ||
cn-hello | 0 | 1,316,978,424 | 47.19% | ||
mfblack | 0 | 15,402,714,895 | 2.85% | ||
mylord1992 | 0 | 1,241,445,852 | 47.19% | ||
threejay | 0 | 801,981,787 | 1.5% | ||
candy.tang | 0 | 12,543,285,098 | 100% | ||
kgame | 0 | 1,602,251,665 | 47.19% | ||
hertz300 | 0 | 2,448,771,601 | 47.19% | ||
koei | 0 | 1,055,767,387 | 47.19% | ||
nympheas | 0 | 8,596,283,530 | 37.75% | ||
aaronli.sct | 0 | 731,584,481 | 10% | ||
steem-drivers | 0 | 908,222,712 | 47.19% | ||
triplea.bot | 0 | 1,027,250,113 | 3% | ||
steem.leo | 0 | 33,078,592,684 | 3% | ||
luismar1978 | 0 | 8,189,917,541 | 70% | ||
xiaoq.sports | 0 | 1,584,859,590 | 47.19% | ||
freddio.sport | 0 | 3,382,569,447 | 15% | ||
hykwf678233 | 0 | 574,758,536 | 47.19% | ||
asteroids | 0 | 3,175,964,664 | 2.7% | ||
hykwf233 | 0 | 23,122,104,535 | 47.19% | ||
botante | 0 | 2,732,238,928 | 0.75% | ||
spt-skillup | 0 | 412,446,658,346 | 10% | ||
ericetchen | 0 | 804,930,780 | 47.19% | ||
stevewu | 0 | 2,499,475,078 | 47.19% | ||
kristinasiu | 0 | 883,833,011 | 47.19% | ||
maxuvd | 0 | 20,381,610,707 | 6% | ||
trevorlp97 | 0 | 5,126,546,195 | 47.19% | ||
btscn | 0 | 215,386,517,768 | 50% | ||
freedomteam2019 | 0 | 1,425,249,336 | 20% | ||
annzhao | 0 | 1,075,195,037 | 47.19% | ||
cn-trail | 0 | 121,038,868 | 47.19% | ||
cnbuddy-reward | 0 | 34,694,728,887 | 47.19% | ||
gerbo | 0 | 0 | 3% | ||
ladyalkaid | 0 | 695,433,680 | 47.19% | ||
lnakuma | 0 | 5,837,780,986 | 47.19% | ||
ribary | 0 | 955,793,087 | 1.5% | ||
kenchung1 | 0 | 16,750,516,980 | 47.19% | ||
mice-k | 0 | 14,945,721,145 | 3% | ||
steem.buzz | 0 | 788,445,491 | 47.19% | ||
catanknight | 0 | 958,046,242 | 47.19% | ||
lovequeen | 0 | 435,745,503,123 | 100% | ||
hiveyoda | 0 | 4,290,948,190 | 2% | ||
visionaer3003 | 0 | 98,177,123,204 | 3% | ||
polish.hive | 0 | 8,106,989,159 | 3% | ||
littleksroad | 0 | 101,023,815,124 | 47.19% | ||
dcityrewards | 0 | 96,010,761,314 | 3% | ||
portraits | 0 | 0 | 25% | ||
kitrewq000 | 0 | 1,428,053,632 | 47.19% | ||
kikoxixi | 0 | 177,697,974 | 47.19% | ||
jywahaha | 0 | 261,521,232,553 | 47.19% | ||
musiccccat | 0 | 20,208,092,298 | 47.19% | ||
alwaysthinking | 0 | 71,445,852 | 47.19% | ||
hivecur | 0 | 76,662,393,529 | 3% | ||
logicforce | 0 | 865,425,771 | 23.59% | ||
asa-raw | 0 | 736,564,481,157 | 20% | ||
xiaomalailiao | 0 | 1,626,116,523 | 47.19% | ||
weiweilove | 0 | 17,433,803,555 | 47.19% | ||
hatschi0773 | 0 | 11,033,934,571 | 3% | ||
hivecur2 | 0 | 45,716,447,876 | 10% | ||
zeteli | 0 | 7,840,293,889 | 47.19% | ||
dagobert007 | 0 | 110,868,963,376 | 3% |