用于从xml

时间:2015-10-22 17:51:15

标签: xpath xslt-2.0

每个商品标签都有内容:编码的子标签。任何人都可以建议我应该是用于检索组织名称,职称和工作ID的xpath表达式吗?

我使用过这个XPath表达式: /系统的数据结构/索引/内容/ RSS //项/内容:编码

但它给我一个错误,说“没有声明带有前缀'内容'的命名空间。”

尝试使用此表达式: substring-before(substring-after(/ system-data-structure / index / content / rss // item,“”),“”)

它检索完整的第一行为 String ='组织名称:校园娱乐'

但是我想动态地使用xpath检索组织的名称,同样用于作业标题和作业ID。

欣赏你对此的看法。

谢谢, NAV。

                <?xml version="1.0" encoding="UTF-8"?>
            <system-data-structure>
                <index type="block">
                <content>
                    <rss
                    xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
                    <channel>
                        <title>Work Study Jobs</title>
                        <link>https://rss.myinterfase.com/rss/tamuc_Work_Study_Jobs.xml</link>
                        <description>Work Study Jobs</description>
                        <item>
                        <title>Campus Recreation</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>Campus Recreation</td></tr><tr><td><b>Job Title:</b></td><td>Business Center Attendant</td></tr><tr><td><b>Job ID:</b></td><td>3190</td></tr><tr><td><b>Job Description:</b></td><td>Please come to the MRC front desk to receive an application.


            Primary Function: Responsible for all selling memberships, course registrations, lockers, personal trainer package, trips 
            and clinics. Individuals should be customer service orientated, have cash handling skills, and should be proficient in filling 
            out paperwork. 
            Position Primary Responsibilities: 
            ? Responsible for cash handling and reconciliation. 
            ? Assist patrons in acquiring memberships, lockers, and other department registrations and sales. 
            ? Answer any inquiries and questions concerning the facility, department, and university.
            ? Enforce all facility, department, and university policies.
            ? Attend all required staff meetings.
            ? Assist in overall implementation of the recreation customer service model. 
            ? Maintain all records, forms and associated paperwork within Operations and Member Services. 
            ? Utilize opportunities set forth by the department for personal and professional development.
            ? Other duties as assigned.

            Please come to the MRC front desk to receive an application.
            </td></tr><tr><td><b>Qualifications:</b></td><td>Required Qualifications: Applicant must be customer service oriented with an emphasis on team work and initiative. 
            Must be current student in good standing with the university and be able to work a minimum of twelve hours a week. 
            Preferred Qualifications: Individuals with customer service backgrounds and have some cash handling skills. </td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Texas</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=onvh%2fXSkEnBl5vmVrydzlw%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>Campus Recreation</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>Campus Recreation</td></tr><tr><td><b>Job Title:</b></td><td>Spartan</td></tr><tr><td><b>Job ID:</b></td><td>3191</td></tr><tr><td><b>Job Description:</b></td><td>Please come to the MRC front desk to receive an application.


            Primary Function: To provide behind the scenes logistical support. 
            Position Primary Responsibilities: 
            ? Review and assess all work orders in order to properly ensure completion. 
            ? Assist with maintenance of all equipment.
            ? Submit appropriate work orders to physical plant/SSC. 
            ? Review all work orders submitted to SSC to ensure satisfactory completion. 
            ? Adopt and learn in a fast pace environment.
            ? Enforce all facility, department, and university policies.
            ? Attend all required staff meetings.
            ? Assist in overall implementation of the recreation customer service model. 
            ? Maintain all records, forms and associated paperwork within Operations and Member Services. 
            ? Utilize opportunities set forth by the department for personal and professional development.
            ? Other duties as assigned.

            Please come to the MRC front desk to receive an application.
            </td></tr><tr><td><b>Qualifications:</b></td><td>Required Qualifications: Applicant must be customer service oriented with an emphasis on team work and initiative. 
            Must be current student in good standing with the university and be able to work a minimum of twelve hours a week. 
            Preferred Qualifications: Individuals with customer service backgrounds, experience using tools, with the ability to learn 
            and absorb information in a timely manner.</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Texas</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=fd5z58VEi9+8g1we0bvm+A%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>Texas AandM Commerce Career Development</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>Texas A&M Commerce Career Development</td></tr><tr><td><b>Job Title:</b></td><td>Work-Study Student Worker</td></tr><tr><td><b>Job ID:</b></td><td>3517</td></tr><tr><td><b>Job Description:</b></td><td>Skills:
            • Strong multitasking skills
            • Strong customer service skills
            • Ability to work in a fast-paced work environment
            • Excellent listening, verbal, and written communication
            • Strong work-ethic
            • Willingness to learn and improve
            • Self-motivated
            • Punctual
            • Trustworthy
            • Knowledge of Microsoft Office
            • Strong computer and technical skills
            • Preferred knowledge of Adobe InDesign, Photoshop, and Social Media

            Key Responsibilities:
            • Schedule appointments
            • Maintain documents and spreadsheets
            • Provide quality customer service
            • Input survey results into C3M database
            • Research and analyze information
            • Assist with answering phone calls 
            • Organize and maintain front desk and kiosk
            • Prepare materials for all programs and events
            • Collaborate and communicate with supervisor
            </td></tr><tr><td><b>Qualifications:</b></td><td>• Must have work-study permit for Summer/Fall 2015
            • Business professional attire
            • Freshman, Sophomore, or Junior Classification
            </td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, TX</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=Otc5yF6%2fxIRICI7NqpV7Ng%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>Radio-TV</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>Radio-TV</td></tr><tr><td><b>Job Title:</b></td><td>Work study assistant</td></tr><tr><td><b>Job ID:</b></td><td>4324</td></tr><tr><td><b>Job Description:</b></td><td>Assist Radio-TV faculty with courses and other activities in the RTV program, as required.  </td></tr><tr><td><b>Qualifications:</b></td><td>Student in good standing with TAMU-C. Good work habits, dependable. Good writing and communications skills. RTV majors or minors preferred.</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Texas</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=TPYe4By+uUqEucAgjbexbA%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>KETR-FM</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>KETR-FM</td></tr><tr><td><b>Job Title:</b></td><td>PT Content producer</td></tr><tr><td><b>Job ID:</b></td><td>4348</td></tr><tr><td><b>Job Description:</b></td><td>88.9 KETR-FM, this region’s largest FM news operation, is seeking a part-time content producer to edit and produce audio on an assignment-by-assignment basis. Flexible hours, electronic workload management.

            This position may, after some training, become hands-off, with minimal supervision, so long as the assigned production schedule is met.

            KETR’s part-time employees are expected to arrive to work on-time ready to work on whatever project is necessary at the time. Employees must be professionally dressed in attire appropriate to the duties and assignments they may encounter on a regular basis. KETR’s employees are expected to be considerate internet denizens; they are expected, insofar as they may represent KETR or Texas A&M University-Commerce to the public at any time, to refrain from improper, antagonistic, tone-deaf, or other generally inappropriate activity that may be viewable by KETR audience members.

            Position open until filled. Hourly pay commensurate with experience, as budget allows. Preference given to work-study-eligible students.
            </td></tr><tr><td><b>Qualifications:</b></td><td>Applicant must possess the following skills:
            -Proficiency with digital audio multitrack editing software (Adobe Audition, Cool Edit, Nuendo, CakeWalk, or similar)
            -Ability to manage and produce rich, high-quality multitrack productions
            -A basic understanding of the differences in audio file formats, bit rates, and digital file quality – bonus if experience successfully converting audio formats
            -Ability to work under deadlines and in occasionally high-pressure situations
            -Ability to communicate effectively (Marked by consistently professional conversations face-to-face, on the telephone, in email/text. Able to spell and use grammar properly. Able to effectively describe complex scenarios verbally.)
            -Punctuality
            </td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Texas</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=vUzXtrcdYNxcVq7ph91YHQ%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>TAMUC Twin Oaks Blueberry Farm</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>TAMUC Twin Oaks Blueberry Farm</td></tr><tr><td><b>Job Title:</b></td><td>Cook</td></tr><tr><td><b>Job ID:</b></td><td>4360</td></tr><tr><td><b>Job Description:</b></td><td>Make Breads, Cakes, Cookies, Jams, Preserves. etc</td></tr><tr><td><b>Qualifications:</b></td><td>Willingness to learn and work hard!</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Tx</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=T2ER1EhNFHTsTcThc+zCNA%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>Applied Linguistics Lab, Literature and Languages</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>Applied Linguistics Lab, Literature & Languages</td></tr><tr><td><b>Job Title:</b></td><td>Work Study Research Assistant</td></tr><tr><td><b>Job ID:</b></td><td>4362</td></tr><tr><td><b>Job Description:</b></td><td>We have an open position to work on a research project in the Applied Linguistics Laboratory. This project has the potential to improve the life of people who suffer from a speech impairment. Your duties will include listening to audio recordings of people with a speech impairment and transcribing or cleaning transcripts of what is said on the recordings. Other duties include, anonymizing the transcripts to protect the identity of the participants. The duties may vary as new needs arise. 

            This work has the potential to change the life of people who have a speech impairment because the data will be used to improve the computerized speech devices they use at work. </td></tr><tr><td><b>Qualifications:</b></td><td>General knowledge of Microsoft Office and willingness to work in a research capacity a plus

            The selected applicant will have the opportunity to work along a graduate student and will receive basic research training. It is a great opportunity to develop skills employed in research in the human and linguistics sciences.</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=IKga0WwsxdvV0BjLGXec9Q%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>TAMUC Twin Oaks Blueberry Farm</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>TAMUC Twin Oaks Blueberry Farm</td></tr><tr><td><b>Job Title:</b></td><td>Clerk</td></tr><tr><td><b>Job ID:</b></td><td>4363</td></tr><tr><td><b>Job Description:</b></td><td>Work in the shop and help run the farmers market</td></tr><tr><td><b>Qualifications:</b></td><td>Willing to Work</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Tx</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=AGrpMCBOb3PAOO8%2fNB4xTg%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>TAMUC Twin Oaks Blueberry Farm</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>TAMUC Twin Oaks Blueberry Farm</td></tr><tr><td><b>Job Title:</b></td><td>Marketing Assistant </td></tr><tr><td><b>Job ID:</b></td><td>4364</td></tr><tr><td><b>Job Description:</b></td><td>Come up with new ways to help promote and increase sales</td></tr><tr><td><b>Qualifications:</b></td><td>Must be Willing to Work </td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Tx</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=H8e5A6cC56e2VCqn%2fRu0NQ%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>School of Agriculture</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>School of Agriculture</td></tr><tr><td><b>Job Title:</b></td><td>Student worker</td></tr><tr><td><b>Job ID:</b></td><td>4365</td></tr><tr><td><b>Job Description:</b></td><td>Assist with red-banded sinkbug research grant</td></tr><tr><td><b>Qualifications:</b></td><td>Ability to follow directions</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, TX</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=2mJ0m68keNNyRVbKLk1+mw%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>TAMUC Twin Oaks Blueberry Farm</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>TAMUC Twin Oaks Blueberry Farm</td></tr><tr><td><b>Job Title:</b></td><td>Farm Hand</td></tr><tr><td><b>Job ID:</b></td><td>4368</td></tr><tr><td><b>Job Description:</b></td><td>Varies Day to Day </td></tr><tr><td><b>Qualifications:</b></td><td>Willing to work outside</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Tx</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=sOCrjK73HpHBxX1zl7GKjQ%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                        <item>
                        <title>Educator Certification</title>
                        <content:encoded>
                            <![CDATA[<table cellpadding='1' cellspacing='2'><tr><td><b>Organization Name:</b></td><td>Educator Certification</td></tr><tr><td><b>Job Title:</b></td><td>Student Worker (Work Study)</td></tr><tr><td><b>Job ID:</b></td><td>4378</td></tr><tr><td><b>Job Description:</b></td><td>Student Worker Position that qualifies for Work Study -  general office duties & responsibilities, front desk reception, answer phones, filing, data entry, making copies, shredding, creating files, scanning documents</td></tr><tr><td><b>Qualifications:</b></td><td>Computer Skills, Knowledge of computer applications (word, excel) organization skills, effective written & oral communication skills, integrity, punctuality & dependability</td></tr><tr><td><b>Job Location (City, State):</b></td><td>Commerce, Texas</td></tr><tr><td colspan='2'><b><a href='https://www.myinterfase.com/tamuc/job_view.aspx?token=2%2fMOKwRjnrGCpGet1xK1zg%3d%3d'>Click to View More</a></b></td></tr></table>]]>
                        </content:encoded>
                        </item>
                    </channel>
                    </rss>
                </content>
                <path>/CampusLife/CampusServices/CareerDevelopment/Students/CDRSS</path>
                <site>CAMPUSLIFE</site>
                <name>CDRSS</name>
                <display-name>CD RSS</display-name>
                </index>
            </system-data-structure>

以下是使用的XSLT:

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

        <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:param name="DevName">Software Engineer</xsl:param>
        <xsl:template match="/">
          <html>
          <body>
          <h2>My RSS FEED</h2>
          <table border="1">
            <tr bgcolor="#9acd32">
              <th>Organizantion</th>
              <th>Job Title</th>
              <th>Job Id</th>
              <th>Job Description</th>
            </tr>
            <xsl:for-each select="/system-data-structure/index/content/rss/channel/item">
            <tr>
              <td>substring-before(substring-after(/system-data-structure/index/content/rss//item,"<tr>"), "/tr>")</td>
              <td><xsl:value-of select="title"/></td>
              <td><xsl:value-of select="$DevName"/></td>
              <td>123421</td>
            </tr>
           </xsl:for-each>
          </table>
          </body>
          </html>
        </xsl:template>

        </xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

那些CDATA部分包含HTML所以我建议使用像Saxon 9 PE或EE这样的XSLT 2.0处理器,它提供了解析HTML的扩展函数:

<xsl:stylesheet
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="content saxon xhtml">
  <xsl:template match="/">
    <html>
      <body>
        <h2>My RSS FEED</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Organization</th>
            <th>Job Title</th>
            <th>Job Id</th>
            <th>Job Description</th>
          </tr>
          <xsl:for-each select="/system-data-structure/index/content/rss/channel/item">
            <tr>
                <xsl:variable name="table-data" select="saxon:parse-html(content:encoded)"/>
                <xsl:apply-templates select="$table-data//xhtml:table/xhtml:tr[position() lt 5]/xhtml:td[2]"/>
              </tr>
            </xsl:for-each>
          </table>
        </body>
      </html>
    </xsl:template>

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

  </xsl:stylesheet>