2009-08-14 11 views
5

का उपयोग कर मैं देख रहा हूं कि सैक्सन 9.1.0.7 का उपयोग करके काम कर रहे एक साधारण बाहरी लुकअप को प्राप्त करने का प्रयास कर मेरे बालों से क्या बचा है।एक्सएसएलटी 2.0 बाहरी लुकअप कुंजी() और दस्तावेज़()

<something> 
    <monkey> 
     <genrecode>AAA</genrecode> 
    </monkey> 
    <monkey> 
     <genrecode>BBB</genrecode> 
    </monkey> 
    <monkey> 
     <genrecode>ZZZ</genrecode> 
    </monkey> 
    <monkey> 
     <genrecode>ZER</genrecode> 
    </monkey> 
</something> 

तब देखने फ़ाइल है GenreSet_124.xml:

मैं एक साधारण स्रोत फ़ाइल dummy.xml है

<GetGenreMappingObjectsResponse> 
    <tuple> 
     <old> 
     <GenreMapping DepartmentCode="AAA" 
         DepartmentName="AND - NEWS AND CURRENT AFFAIRS" 
         Genre="10 - NEWS"/> 
     </old> 
    </tuple> 
    <tuple> 
     <old> 
     <GenreMapping DepartmentCode="BBB" 
         DepartmentName="AND - NEWS AND CURRENT AFFAIRS" 
         Genre="11 - NEWS"/> 
     </old> 
    </tuple> 

    ... lots more 
</GetGenreMappingObjectsResponse> 

मैं क्या ' मैं हासिल करने की कोशिश कर रहा हूं बस "शैली" पकड़ने के लिए है "विभाग" कोड के आधार पर मूल्य।

तो मेरी XSL लगता है:

... 
<!-- Set up the genre lookup key --> 
<xsl:key name="genre-lookup" match="GenreMapping" use="@DepartmentCode"/> 


<xsl:variable name="lookupDoc" select="document('GenreSet_124.xml')"/> 

<xsl:template match="/something"> 
<stuff> 
    <xsl:for-each select="monkey"> 
     <Genre> 

     <xsl:apply-templates select="$lookupDoc"> 
     <xsl:with-param name="curr-label" select="genrecode"/> 
     </xsl:apply-templates> 

     </Genre> 
    </xsl:for-each> 
</stuff> 
</xsl:template> 

<xsl:template match="GetGenreMappingObjectsResponse"> 
    <xsl:param name="curr-genrecode"/> 

    <xsl:value-of select="key('genre-lookup', $curr-genrecode)/@Genre"/> 

</xsl:template> 

...


मुद्दा रहा है कि मैं कुछ भी नहीं वापस पाने के लिए है। मैं वर्तमान में सिर्फ जब भी मैं टेम्पलेट मैच = प्रवेश किया "GetGenreMappingObjectsResponse" यह सिर्फ बाहर सभी पाठ हर GenreMapping से प्रिंट होगा GenreMapping के बच्चे तत्व के रूप में

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

मैं GenreMapping की विशेषताओं होने के लिए सभी देखने डेटा स्थानांतरित कर दिया हो, पहले से (विभाग कोड, विभाग नाम, शैली)!

मैं अपने जीवन के लिए यह नहीं समझ सकता कि मैं क्या गलत कर रहा हूं। किसी भी मदद/सुझावों की सराहना की जाएगी।

कृपया वर्तमान वास्तविक XSLT सूची पाते हैं:।

<?xml version="1.0"?> 
<xsl:stylesheet version="2.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<!-- Define the global parameters --> 
<xsl:param name="TransformationID"/> 
<xsl:param name="TransformationType"/> 

<!-- Specify that XML is the desired output type --> 
<xsl:output method="xml" encoding="UTF-8" indent="yes"/> 

<!-- Set up the genre matching capability --> 
<xsl:key name="genre-lookup" match="GenreMapping" use="@DepartmentCode"/> 

<xsl:variable name="documentPath"><xsl:value-of select="concat('GenreSet_',$TransformationID,'.xml')"/></xsl:variable> 
<xsl:variable name="lookupDoc" select="document($documentPath)"/> 

<!-- Start the first match on the Root level --> 
<xsl:template match="/something"> 
<stuff> 
    <xsl:for-each select="monkey"> 
     <Genre> 
     <xsl:apply-templates select="$lookupDoc/*"> 
     <xsl:with-param name="curr-genrecode" select="string(genrecode)"/> 
     </xsl:apply-templates> 
     </Genre> 
    </xsl:for-each> 
</stuff> 
</xsl:template > 

<xsl:template match="GetGenreMappingObjectsResponse"> 
    <xsl:param name="curr-genrecode"/> 
    <xsl:value-of select="key('genre-lookup', $curr-genrecode, $lookupDoc)/@Genre"/> 
</xsl:template> 
</xsl:stylesheet> 

TransformationID alway 124 है (ताकि सही देखने फ़ाइल खोला है प्रकार सिर्फ एक नाम है कि मैं वर्तमान में उपयोग नहीं कर रहा है, लेकिन के लिए इच्छुक है

एक key समारोह के तीन पैरामीटर संस्करण है तीसरे पैरामीटर आप रूट नोड आप कुंजी पर काम करना चाहता (निर्दिष्ट कर सकते हैं:

+0

क्या एक्सएसएलटी कंपाइलर आप उपयोग कर रहे हैं? – Welbog

+0

सैक्सन-बी 9.1.0.7 –

+0

आंकड़े। मैं उस से परिचित नहीं हूँ। शायद बाद में तोमालक आ जाएगा और आपकी मदद करेगा। क्या चाबी रहित विधि काम करती है? – Welbog

उत्तर

7

XSLT 2.0 में दो तरीकों से कर सकते हैं कि आप क्या चाहते हैं। डिफ़ॉल्ट रूप से यह है हमेशा मुख्य दस्तावेज़ की जड़):

<xsl:value-of select="key('genre-lookup', $curr-genrecode,$lookupDoc)/@Genre"/> 

एक और तरीका है $lookupDoc नोड के अंतर्गत key समारोह का उपयोग करने के लिए है:

<xsl:value-of select="$lookupDoc/key('genre-lookup', $curr-genrecode)/@Genre"/> 

इन तरीकों में से दोनों XSLT 2.0 specification on keys में दर्ज कर रहे हैं, और नहीं होगा एक्सएसएलटी 1.0 में काम करें।

पूर्णता के लिए, यदि आप XSLT 1.0 तक सीमित हैं तो आपको कुंजी का उपयोग न करने के लिए इसे फिर से लिखना होगा।

<xsl:value-of select="$lookupDoc//GenreMapping[@DepartmentCode = $curr-genrecode]/@Genre"/> 

अहा! समस्या है आपके apply-templates कॉल में आपके द्वारा अपेक्षित अपेक्षा के बजाय डिफ़ॉल्ट टेम्पलेट कॉल कर रहा है, इसलिए पैरामीटर गुम हो रहा है।

यह यह करने के लिए परिवर्तित करें:

<xsl:apply-templates select="$lookupDoc/*"> 
    <xsl:with-param name="curr-genrecode" select="string(genrecode)"/> 
</xsl:apply-templates> 

कि अपने टेम्पलेट ठीक से कॉल करेंगे और कुंजी काम करना चाहिए।

तो अंतिम XSLT चादर कुछ इस तरह दिखना चाहिए:

<xsl:variable name="lookupDoc" select="document('XMLFile2.xml')"/> 
    <xsl:key name="genre-lookup" match="GenreMapping" use="@DepartmentCode"/> 
    <xsl:template match="/something"> 
    <stuff> 
     <xsl:for-each select="monkey"> 
     <Genre> 
      <xsl:apply-templates select="$lookupDoc/*"> 
      <xsl:with-param name="curr-genrecode" select="string(genrecode)"/> 
      </xsl:apply-templates> 
     </Genre> 
     </xsl:for-each> 
    </stuff> 
    </xsl:template> 
    <xsl:template match="GetGenreMappingObjectsResponse"> 
    <xsl:param name="curr-genrecode"/> 
    <xsl:value-of select="key('genre-lookup',$curr-genrecode,$lookupDoc)/@Genre"/> 
    </xsl:template> 

(Source of information)

+0

HI वहाँ है, प्रतिक्रिया के लिए धन्यवाद। मैंने इन दोनों को पहले से ही (और अब पुनः प्रयास किया है) (मास्टर टेम्पलेट के भीतर से, मैं इस फॉर्म का उपयोग करके लागू-टेम्पलेट को कॉल नहीं करता) और दोनों कुछ भी वापस नहीं कर पाए हैं। मुझे अभी भी खाली तत्व मिलते हैं ?! कुछ ऐसा होना चाहिए जो मैं कुंजी के सेटअप में गलत कर रहा हूं? –

+0

का संबंध है यह आपके एक्सएसएलटी कंपाइलर के साथ एक विशिष्ट समस्या हो सकती है, लेकिन '$ lookupDoc/*' का उपयोग करके आपके आधार को कवर करना चाहिए। – Welbog

+0

हैलो फिर से, अद्यतन कोड का उपयोग करके मुझे खाली तत्व नहीं मिलते हैं, मैं उन्हें व्हाइटस्पेस (24 लाइनों के लायक) से भरा करता हूं। अब मैं वास्तव में परेशान हूं। –

0

ठीक है, तो यह एक बिट मानसिक है और मैं इसे समझने के लिए दावा नहीं करते हैं, लेकिन यह काम करता है (सॉफ्टवेयर में एक कैरियर की तरह लगता है)।

मेरा मुद्दा यह था कि जब मैं लागू-टेम्पलेट्स को कॉल करता हूं और बाहरी दस्तावेज़ में एक चर के रूप में पास करता हूं तो यह कभी भी "जेनरमैपिंग" नामक किसी भी टेम्पलेट से मेल नहीं खाता है।

इसलिए मैंने इसे पकड़ने के लिए वाइल्डकार्ड का उपयोग किया, साथ ही लागू-टेम्पलेट्स को कॉल करते समय मैंने नोड सेट को उस बच्चे के रूप में कम कर दिया जिसकी मुझे रूचि थी। यह बहुत अच्छा था कि मैं नोड का नाम प्रिंट कर सकता था और "जेनरमैपिंग" देखें, फिर भी यह कभी भी कभी भी "*" टेम्पलेट पर जाने के बजाय "जेनरमैपिंग" नामक किसी भी टेम्पलेट में नहीं गया था।

इसका क्या अर्थ है कि मेरा नया टेम्पलेट मैच हर सिंगल जेनरमैपिंग नोड के लिए बुलाया जाता है, इसलिए यह थोड़ा अक्षम हो सकता है। मुझे जो एहसास हुआ वह सब कुछ था जो मुझे करने की ज़रूरत थी, अगर एक अनुमानित मिलान हुआ तो प्रिंट करना कभी-कभी प्रिंट किया गया था। सभी जिनमें से

... 
<xsl:template match="/something"> 
<stuff> 
    <xsl:for-each select="monkey"> 
     <Genre> 
     <key_value><xsl:value-of select="genrecode"/></key_value> 
     <xsl:variable name="key_val"><xsl:value-of select="genrecode"/></xsl:variable> 
     <code> 
     <xsl:apply-templates select="$lookupDoc/*/*/*/*"> 
     <xsl:with-param name="curr-genrecode" select="string(genrecode)"/> 
     </xsl:apply-templates> 

     </code> 
     </Genre> 
    </xsl:for-each> 
</stuff> 
</xsl:template > 


<xsl:template match="*"> 
    <xsl:param name="curr-genrecode"/> 
    <xsl:value-of select=".[@DepartmentCode = $curr-genrecode]/@Genre"/> 
</xsl:template> 
... 

उत्पादन:

तो यह यह अब (कोई भी इस्तेमाल किया कुंजी) की तरह लग रहा ध्यान दें, पिछले key_value सही ढंग से एक कोड प्रविष्टि नहीं है के रूप में वहाँ में कोई मुकाबला नहीं है लुकअप दस्तावेज़

<?xml version="1.0" encoding="UTF-8"?> 
<stuff xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <Genre> 
     <key_value>AAA</key_value> 
     <code>10 - NEWS</code> 
    </Genre> 
    <Genre> 
     <key_value>AAA</key_value> 
     <code>10 - NEWS</code> 
    </Genre> 
    <Genre> 
     <key_value>BBB</key_value> 
     <code>11 - NEWS</code> 
    </Genre> 
    <Genre> 
     <key_value>SVVS</key_value> 
     <code/> 
    </Genre> 
</stuff> 

एक पोस्टकोड पर उत्तर दें। मदद Welbog के लिए धन्यवाद।

+0

मुझे खुशी है कि आपको एक कामकाजी समाधान मिला, भले ही यह एक अजीब है। – Welbog

संबंधित मुद्दे