속성이 없거나 비어있는 경우 내 변수를 false()
으로 설정합니다.속성이 비어 있거나 존재하지 않는 경우 XSLT 부울 변수를 true로 설정하는 방법은 무엇입니까?
XML :
<cd name="One" />
<cd name="Two" incollection=""/>
<cd name="Three" incollection="true"/>
XSL :
<!-- this will only set to false when attribute is missing -->
<xsl:variable name="incollection" select="boolean(@incollection)"/>
<!-- this will set to false both when attribute is missing or is empty-->
<xsl:variable name="incollection2" select="boolean(@incollection) or @incollection=''"/>
두 번째 표현은 나를 위해 작동하지만, 나는이 표현을 쓰기의 더 나은 더 관용적 인 방법이 있었는지 궁금 해서요 ? 당신은 누구의 문자열 속성을 제외 할 경우
string-length(@incollection) > 0
:
@empo XSLT 프로세서를 사용하고 계십니까? 예를 들어 Chrome 또는 Java Xalan에 내장 된 XSLT 프로세서에서 작동하지 않습니다. –
좋은 질문입니다. +1. 두 가지 대체 one-liner XPath 식에 대한 내 대답을 참조하십시오. –