{"id":245883,"date":"2022-07-05T09:12:51","date_gmt":"2022-07-05T01:12:51","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=245883"},"modified":"2022-06-23T18:15:24","modified_gmt":"2022-06-23T10:15:24","slug":"xsl-choose-element","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/xsl-choose-element.html","title":{"rendered":"XSLT <xsl:choose>\u5143\u7d20\u6982\u8ff0"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n<\/p>\n

<xsl:choose> \u5143\u7d20\u7528\u4e8e\u7ed3\u5408 <xsl:when> \u548c <xsl:otherwise> \u6765\u8868\u8fbe\u591a\u91cd\u6761\u4ef6\u6d4b\u8bd5\u3002<\/p>\n

<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

<\/p>\n

<xsl:choose> \u5143\u7d20<\/h2>\n

<\/strong><\/div>\n

\u8bed\u6cd5<\/strong><\/p>\n

\r\n<xsl:choose>\r\n<xsl:when test=\"expression<\/i>\">   \r\n... some output ...\r\n<\/xsl:when>  \r\n<xsl:otherwise>     \r\n... some output ....  \r\n<\/xsl:otherwise>\r\n<\/xsl:choose>\r\n<\/pre>\n
\u5728\u4f55\u5904\u653e\u7f6e\u9009\u62e9\u6761\u4ef6<\/strong><\/div>\n

\u5982\u9700\u63d2\u5165\u9488\u5bf9 XML \u6587\u4ef6\u7684\u591a\u91cd\u6761\u4ef6\u6d4b\u8bd5\uff0c\u8bf7\u5411 XSL \u6587\u4ef6\u6dfb\u52a0 <xsl:choose>\u3001<xsl:when> \u4ee5\u53ca <xsl:otherwise>\u5143\u7d20\uff1a<\/p>\n

\u5b9e\u4f8b<\/p>\n

<?<\/span>xml<\/span> <\/span>version<\/span>=<\/span>\"<\/span>1.0<\/span>\"<\/span> <\/span>encoding<\/span>=<\/span>\"<\/span>UTF-8<\/span>\"<\/span>?><\/span>\r\n<\/span><<\/span>xsl:stylesheet<\/span> <\/span>version<\/span>=<\/span>\"<\/span>1.0<\/span>\"<\/span>\r\n<\/span>xmlns:xsl<\/span>=<\/span>\"<\/span>http:\/\/www.w3.org\/1999\/XSL\/Transform<\/span>\"<\/span>><\/span>\r\n \r\n<\/span><<\/span>xsl:template<\/span> <\/span>match<\/span>=<\/span>\"<\/span>\/<\/span>\"<\/span>><\/span>\r\n  <\/span><<\/span>html<\/span>><\/span>\r\n  <\/span><<\/span>body<\/span>><\/span>\r\n  <\/span><<\/span>h2<\/span>><\/span>My CD Collection<\/span><\/<\/span>h2<\/span>><\/span>\r\n  <\/span><<\/span>table<\/span> <\/span>border<\/span>=<\/span>\"<\/span>1<\/span>\"<\/span>><\/span>\r\n    <\/span><<\/span>tr<\/span> <\/span>bgcolor<\/span>=<\/span>\"<\/span>#9acd32<\/span>\"<\/span>><\/span>\r\n      <\/span><<\/span>th<\/span>><\/span>Title<\/span><\/<\/span>th<\/span>><\/span>\r\n      <\/span><<\/span>th<\/span>><\/span>Artist<\/span><\/<\/span>th<\/span>><\/span>\r\n    <\/span><\/<\/span>tr<\/span>><\/span>\r\n    <\/span><<\/span>xsl:for-each<\/span> <\/span>select<\/span>=<\/span>\"<\/span>catalog\/cd<\/span>\"<\/span>><\/span>\r\n    <\/span><<\/span>tr<\/span>><\/span>\r\n      <\/span><<\/span>td<\/span>><\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>title<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n      <\/span><<\/span>xsl:choose<\/span>><\/span>\r\n        <\/span><<\/span>xsl:when<\/span> <\/span>test<\/span>=<\/span>\"<\/span>price <\/span>&gt;<\/span> 10<\/span>\"<\/span>><\/span>\r\n          <\/span><<\/span>td<\/span> <\/span>bgcolor<\/span>=<\/span>\"<\/span>#ff00ff<\/span>\"<\/span>><\/span>\r\n          <\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>artist<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n        <\/span><\/<\/span>xsl:when<\/span>><\/span>\r\n        <\/span><<\/span>xsl:otherwise<\/span>><\/span>\r\n          <\/span><<\/span>td<\/span>><\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>artist<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n        <\/span><\/<\/span>xsl:otherwise<\/span>><\/span>\r\n      <\/span><\/<\/span>xsl:choose<\/span>><\/span>\r\n    <\/span><\/<\/span>tr<\/span>><\/span>\r\n    <\/span><\/<\/span>xsl:for-each<\/span>><\/span>\r\n  <\/span><\/<\/span>table<\/span>><\/span>\r\n  <\/span><\/<\/span>body<\/span>><\/span>\r\n  <\/span><\/<\/span>html<\/span>><\/span>\r\n<\/span><\/<\/span>xsl:template<\/span>><\/span>\r\n \r\n<\/span><\/<\/span>xsl:stylesheet<\/span>><\/span><\/pre>\n

\u4e0a\u9762\u7684\u4ee3\u7801\u4f1a\u5728 CD \u7684\u4ef7\u683c\u9ad8\u4e8e 10 \u65f6\u5411 \"Artist\" \u5217\u6dfb\u52a0\u7c89\u8272\u7684\u80cc\u666f\u989c\u8272\u3002<\/p>\n

\u53e6\u4e00\u4e2a\u5b9e\u4f8b<\/strong><\/div>\n

\u8fd9\u662f\u53e6\u5916\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a <xsl:when>\u5143\u7d20\u7684\u5b9e\u4f8b\uff1a<\/p>\n

\u5b9e\u4f8b<\/p>\n

<?<\/span>xml<\/span> <\/span>version<\/span>=<\/span>\"<\/span>1.0<\/span>\"<\/span> <\/span>encoding<\/span>=<\/span>\"<\/span>UTF-8<\/span>\"<\/span>?><\/span>\r\n<\/span><<\/span>xsl:stylesheet<\/span> <\/span>version<\/span>=<\/span>\"<\/span>1.0<\/span>\"<\/span>\r\n<\/span>xmlns:xsl<\/span>=<\/span>\"<\/span>http:\/\/www.w3.org\/1999\/XSL\/Transform<\/span>\"<\/span>><\/span>\r\n \r\n<\/span><<\/span>xsl:template<\/span> <\/span>match<\/span>=<\/span>\"<\/span>\/<\/span>\"<\/span>><\/span>\r\n  <\/span><<\/span>html<\/span>><\/span>\r\n  <\/span><<\/span>body<\/span>><\/span>\r\n  <\/span><<\/span>h2<\/span>><\/span>My CD Collection<\/span><\/<\/span>h2<\/span>><\/span>\r\n  <\/span><<\/span>table<\/span> <\/span>border<\/span>=<\/span>\"<\/span>1<\/span>\"<\/span>><\/span>\r\n    <\/span><<\/span>tr<\/span> <\/span>bgcolor<\/span>=<\/span>\"<\/span>#9acd32<\/span>\"<\/span>><\/span>\r\n      <\/span><<\/span>th<\/span>><\/span>Title<\/span><\/<\/span>th<\/span>><\/span>\r\n      <\/span><<\/span>th<\/span>><\/span>Artist<\/span><\/<\/span>th<\/span>><\/span>\r\n    <\/span><\/<\/span>tr<\/span>><\/span>\r\n    <\/span><<\/span>xsl:for-each<\/span> <\/span>select<\/span>=<\/span>\"<\/span>catalog\/cd<\/span>\"<\/span>><\/span>\r\n    <\/span><<\/span>tr<\/span>><\/span>\r\n      <\/span><<\/span>td<\/span>><\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>title<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n      <\/span><<\/span>xsl:choose<\/span>><\/span>\r\n        <\/span><<\/span>xsl:when<\/span> <\/span>test<\/span>=<\/span>\"<\/span>price <\/span>&gt;<\/span> 10<\/span>\"<\/span>><\/span>\r\n          <\/span><<\/span>td<\/span> <\/span>bgcolor<\/span>=<\/span>\"<\/span>#ff00ff<\/span>\"<\/span>><\/span>\r\n          <\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>artist<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n        <\/span><\/<\/span>xsl:when<\/span>><\/span>\r\n        <\/span><<\/span>xsl:when<\/span> <\/span>test<\/span>=<\/span>\"<\/span>price <\/span>&gt;<\/span> 9<\/span>\"<\/span>><\/span>\r\n          <\/span><<\/span>td<\/span> <\/span>bgcolor<\/span>=<\/span>\"<\/span>#cccccc<\/span>\"<\/span>><\/span>\r\n          <\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>artist<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n        <\/span><\/<\/span>xsl:when<\/span>><\/span>\r\n        <\/span><<\/span>xsl:otherwise<\/span>><\/span>\r\n          <\/span><<\/span>td<\/span>><\/span><<\/span>xsl:value-of<\/span> <\/span>select<\/span>=<\/span>\"<\/span>artist<\/span>\"<\/span>\/><\/span><\/<\/span>td<\/span>><\/span>\r\n        <\/span><\/<\/span>xsl:otherwise<\/span>><\/span>\r\n      <\/span><\/<\/span>xsl:choose<\/span>><\/span>\r\n    <\/span><\/<\/span>tr<\/span>><\/span>\r\n    <\/span><\/<\/span>xsl:for-each<\/span>><\/span>\r\n  <\/span><\/<\/span>table<\/span>><\/span>\r\n  <\/span><\/<\/span>body<\/span>><\/span>\r\n  <\/span><\/<\/span>html<\/span>><\/span>\r\n<\/span><\/<\/span>xsl:template<\/span>><\/span>\r\n \r\n<\/span><\/<\/span>xsl:stylesheet<\/span>><\/span><\/pre>\n

\u4e0a\u9762\u7684\u4ee3\u7801\u4f1a\u5728 CD \u7684\u4ef7\u683c\u9ad8\u4e8e 10 \u65f6\u5411 \"Artist\" \u5217\u6dfb\u52a0\u7c89\u8272\u7684\u80cc\u666f\u989c\u8272\uff0c\u5e76\u5728 CD \u7684\u4ef7\u683c\u9ad8\u4e8e 9 \u4e14\u4f4e\u4e8e\u7b49\u4e8e 10 \u65f6\u5411 \"Artist\" \u5217\u6dfb\u52a0\u7070\u8272\u7684\u80cc\u666f\u989c\u8272\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8bed\u6cd5 <xsl:choose> <xsl:when test=”expression”&gt […]<\/p>\n","protected":false},"author":1481,"featured_media":245885,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-245883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/245883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=245883"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/245883\/revisions"}],"predecessor-version":[{"id":245888,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/245883\/revisions\/245888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/245885"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=245883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=245883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=245883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}