2017-02-20 1 views
0

XSLTを使用してXMLを変更されたXMLに変換しています。私は条件をチェックしたい:ヘッドラインが非pdfエンドポイントを指している場合、何かをする。以下は私のXMLです:XSLTのURLパターンを比較するには?

<vce> 
    <form> 
     <headlineURL> 
      <a href="http://www.example.com/bin/internal-application.pdf" /> 
     </headlineURL> 
    </form> 
    <form> 
     <headlineURL> 
      <a href="http://www.demo.com" /> 
     </headlineURL> 
    </form> 
    <form> 
     <headlineURL> 
      <a href="http://www.demo-live.in" /> 
     </headlineURL> 
    </form> 
</vce> 

XSLTのwhen条件ではどうしたらいいですか? headlineURLは、すべてのヘルプは高く評価され

<xsl:choose> 
    <xsl:when test= ...> 
    <!-- Do something --> 
    </xsl:when> 
</xsl:choose> 

PDF以外のエンドポイント(例えば「http://www.demo.com」、「」http://www.demo-live.in「)を含んでいる場合、私は条件を実行したい

+0

XSLT 1.0または2.0? –

+0

実際には、IBM Watson Explorerを使用してXMLを変換しています。ここにリンクがあります:https://www.ibm.com/support/knowledgecenter/SS8NLW_10.0.0/com.ibm.swg.im.infosphere.dataexpl.engine.doc/c_xml-xsl-intro.html。 XSLTのバージョンを指定しませんでした。 – Rose

答えて

0

次のXSLT-1.0のコードがあればチェックしません入力headlineURL/a/@href sがチェックが大文字と小文字を区別のみ.pdfをチェックし、ない.PDFです。文字列.pdfで終わらないので、私は必要に応じてチェックする前にケース・中和・テンプレートを追加することをお勧めしたい。

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" />    <!-- output data as XML --> 
    <xsl:strip-space elements="*" />   <!-- remove unnecessary spaces in output --> 

    <xsl:template match="/vce/form/headlineURL"> 
    <xsl:variable name="doExec">    <!-- set variable with predicate --> 
     <xsl:call-template name="ends-with"> <!-- check if input ends-with '.pdf' --> 
     <xsl:with-param name="txt" select="a/@href" /> 
     <xsl:with-param name="ends" select="'.pdf'" /> 
     </xsl:call-template> 
    </xsl:variable> 
    <xsl:if test="$doExec != 'true'"> 
     <xsl:value-of select="a/@href" />: No PDF!!!  <!-- replace this line with the desired output --> 
    </xsl:if> 
    </xsl:template> 

    <!-- XSLT 1.0 version of the function 'ends-with' --> 
    <xsl:template name="ends-with"> 
    <xsl:param name="txt" /> 
    <xsl:param name="ends" /> 
    <xsl:value-of select="substring($txt, string-length($txt) - string-length($ends) +1) = $ends" /> 
    </xsl:template> 

</xsl:stylesheet> 
関連する問題