어떻게 특성 값을 사용할 때 XSLT 으로 알 수 없는 네임스페이스?

StackOverflow https://stackoverflow.com/questions/76204

  •  09-06-2019
  •  | 
  •  

문제

나는 받는 제 3 자의 급 수 없는 특정 네임스페이스의 그래서 나는 현재 가 사용하는 지역 이름()함수에서 내 XSLT 요소를 가져오는 값입니다.그러나 나는 데 필요한 특성 중 하나에서 이러한 요소와 내가 알지 못하는 방법을 할 때 이것을 네가 알 수 없음(따라서 필요한 지역 이름()function).

N.B.내가 사용합니다.net2.0 하는 프로세스 XSLT

샘플 XML:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <id>some id</id>
   <title>some title</title>
   <updated>2008-09-11T15:53:31+01:00</updated>
   <link rel="self" href="http://www.somefeedurl.co.uk" />
   <author>
      <name>some author</name>
      <uri>http://someuri.co.uk</uri>
   </author>
   <generator uri="http://aardvarkmedia.co.uk/">AardvarkMedia script</generator>
   <entry>
      <id>http://soemaddress.co.uk/branded3/80406</id>
      <title type="html">My Ttile</title>
      <link rel="alternate" href="http://www.someurl.co.uk" />
      <updated>2008-02-13T00:00:00+01:00</updated>
      <published>2002-09-11T14:16:20+01:00</published>
      <category term="mycategorytext" label="restaurant">Test</category>
      <content type="xhtml">
         <div xmlns="http://www.w3.org/1999/xhtml">
            <div class="vcard">
               <p class="fn org">some title</p>
               <p class="adr">
                  <abbr class="type" title="POSTAL" />
                  <span class="street-address">54 Some Street</span>
                  ,
                  <span class="locality" />
                  ,
                  <span class="country-name">UK</span>
               </p>
               <p class="tel">
                  <span class="value">0123456789</span>
               </p>
               <div class="geo">
                  <span class="latitude">51.99999</span>
                  ,
                  <span class="longitude">-0.123456</span>
               </div>
               <p class="note">
                  <span class="type">Review</span>
                  <span class="value">Some content</span>
               </p>
               <p class="note">
                  <span class="type">Overall rating</span>
                  <span class="value">8</span>
               </p>
            </div>
         </div>
      </content>
      <category term="cuisine-54" label="Spanish" />
      <Point xmlns="http://www.w3.org/2003/01/geo/wgs84_pos#">
         <lat>51.123456789</lat>
         <long>-0.11111111</long>
      </Point>
   </entry>
</feed>

이 XSLT

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wgs="http://www.w3.org/2003/01/geo/wgs84_pos#" exclude-result-prefixes="atom wgs">
  <xsl:output method="xml" indent="yes"/>

  <xsl:key name="uniqueVenuesKey" match="entry" use="id"/>
  <xsl:key name="uniqueCategoriesKey" match="entry" use="category/@term"/>

  <xsl:template match="/">
    <locations>
      <!-- Get all unique venues -->
      <xsl:for-each select="/*[local-name()='feed']/*[local-name()='entry']">
        <xsl:variable name="CurrentVenueKey" select="*[local-name()='id']" ></xsl:variable>
        <xsl:variable name="CurrentVenueName" select="*[local-name()='title']" ></xsl:variable>
        <xsl:variable name="CurrentVenueAddress1" select="*[local-name()='content']/*[local-name()='div']/*[local-name()='div']/*[local-name()='p'][@class='adr']/*[local-name()='span'][@class='street-address']" ></xsl:variable>
        <xsl:variable name="CurrentVenueCity" select="*[local-name()='content']/*[local-name()='div']/*[local-name()='div']/*[local-name()='p'][@class='adr']/*[local-name()='span'][@class='locality']" ></xsl:variable>
        <xsl:variable name="CurrentVenuePostcode" select="*[local-name()='postcode']" ></xsl:variable>
        <xsl:variable name="CurrentVenueTelephone" select="*[local-name()='telephone']" ></xsl:variable>
        <xsl:variable name="CurrentVenueLat" select="*[local-name()='Point']/*[local-name()='lat']" ></xsl:variable>
        <xsl:variable name="CurrentVenueLong" select="*[local-name()='Point']/*[local-name()='long']" ></xsl:variable>
        <xsl:variable name="CurrentCategory" select="WHATDOIPUTHERE"></xsl:variable>

            <location>
              <locationName>
                <xsl:value-of select = "$CurrentVenueName" />
              </locationName>
              <category>
                <xsl:value-of select = "$CurrentCategory" />
              </category>
              <description>
                  <xsl:value-of select = "$CurrentVenueName" />
              </description>
              <venueAddress>
                <streetName>
                  <xsl:value-of select = "$CurrentVenueAddress1" />
                </streetName>
                <town>
                  <xsl:value-of select = "$CurrentVenueCity" />
                </town>
                <postcode>
                  <xsl:value-of select = "$CurrentVenuePostcode" />
                </postcode>
                <wgs84_latitude>
                  <xsl:value-of select = "$CurrentVenueLat" />
                </wgs84_latitude>
                <wgs84_longitude>
                  <xsl:value-of select = "$CurrentVenueLong" />
                </wgs84_longitude>
              </venueAddress>
              <venuePhone>
                <phonenumber>
                  <xsl:value-of select = "$CurrentVenueTelephone" />
                </phonenumber>
              </venuePhone>
          </location>
        </xsl:for-each>
    </locations>
  </xsl:template>
</xsl:stylesheet>

내가 노력하고 대체$CurrentCategory 변수는 해당 코드를 표시 mycategorytext

도움이 되었습니까?

해결책

가 없 XSLT 편집기를 여기에,하지만 당신은 시도를 사용하여

*[local-name()='category']/@*[local-name()='term']

다른 팁

에 따라 http://www.w3.org/TR/2006/REC-xml-names-20060816/#scoping-defaulting

"기본 네임스페이스 선언에 직접 적용되지 않 속성 이름;의 해석 접두사가 없는 특성에 의해 결정되는 요소에 그들이 나타납니다."

즉 당신의 속성에 없는 네임스페이스입니다.만 사용"@용어".

그냥 조금 더 명확하고,없을 사용하기 위해 필요한 지역 이름()이 문제를 해결합니다.전통적인 방법으로 그것을 다루는 것을 선언하는 접두사에 대한 원자 네임스페이스에서 당신의 XSLT,다음 사용하 xpath 쿼리를 처리합니다.

당신은 이미 얻은 이 선언의 스타일 요소(xmlns:atom="http://www.w3.org/2005/Atom"),그래서 모든 것을 남아 있을 사용하는 것입니다.

으로 나는 이미 설명 특성에 의해 영향을 받지 않는 기본 네임스페이스,그래서 당신의 코드는 다음과 같이(가정하던 추가"xmlns:xhtml='http://www.w3.org/1999/xhtml'"):

      <xsl:for-each select="/atom:feed/atom:entry">
        <xsl:variable name="CurrentVenueKey" select="atom:id" />
        <xsl:variable name="CurrentVenueName" select="atom:title" />
        <xsl:variable name="CurrentVenueAddress1" 
             select="atom:content/xhtml:div/xhtml:div/xhtml:p[@class='adr']/xhtml:span[@class='street-address']" />
        <xsl:variable name="CurrentVenueCity" 
             select="atom:content/xhtml:div/xhtml:div'/xhtml:p[@class='adr']/xhtml:span[@class='locality'] />
...
        <xsl:variable name="CurrentCategory" select="atom:category/@term" />

..... 

지역 이름()매우 유용할 수 있습니다 만약 당신이 정말로 알지 못하는 구조의 XML 을 변화시키지만,이 경우에,수신되면 아무것도 다른 것보다 당신이 무엇을 기대하고,그 틈에서 어떤 경우이다.

난 정말 모르겠어요 왜 당신이 사용하는 지역 이름()지만,공유하는 경우 조금 더 많은 정보를 원하시면 무엇으로 xslt 프로세서에서 사용하고 있와 함께 언어 나는 것을 파악될 수 있습니다.이것을 말 b/c 할 수 있어야 할 뭔가가 다음과 같:

<xsl:stylesheet xmlns="http://www.w3.org/2005/Atom" ..>

<xsl:template match="feed">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="entry">
  ... 
  <xsl:variable name="current-category" select="category/@term" />
  ...
</xsl:template>

두 가지고 도움 당신은 xmlns 선언에서 최고없이 접두사입니다.설정하는 기본 네임스페이스 그래서 당신이 있지 않을 사용하는 네임스페이스 접두사입니다.마찬가지로,당신을 부를 수 있는지 xmlns:a="http://www.w3.org/2005/Atom"'다음'을 선택="a:피드"'.다른 것을 알 수 있을 사용하는'@'용어를 선택하는 특성이 있습니다.일치하는 항목을 찾으려는 경우에는 모든 특성'@*'일 것처럼을 위한 요소입니다.

다시 따라 프로세서에 있는 다른 유용한 도구는 귀하의 처분에게 제공할 수 있습니다 더 많은 정보를 얻을 수 있습니다 그것은 도움이 될 수 있습니다.또한, XSL 우편 목록 수도 또 다른 유용한 자원입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top